cpp-common/bt2: use universal reference for `Graph::addComponent()` initialization...
authorSimon Marchi <simon.marchi@efficios.com>
Wed, 13 Mar 2024 04:27:54 +0000 (00:27 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Tue, 26 Mar 2024 18:56:36 +0000 (14:56 -0400)
I noticed it was not possible to pass data to `Graph::addComponent`
using a temporary object:

    graph->addComponent(*srcCompCls, "source-1", TestSourceData {});

My understanding of it is that the compiler does not consider the
overload with the `InitDataT&` parameter for this, because the temporary
object can't bind to the lvalue reference.

Change these methods to take forwarding references instead.

Change-Id: Icc80239812c325b777ed83e8634302a0c9d72f14
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12049
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
src/cpp-common/bt2/graph.hpp

index c1c6ad09ca932c7fa4e02f23492aa1b14e4f2d4d..0927cd30a0f2483aa22363dcd835844b9239c2f5 100644 (file)
@@ -66,7 +66,7 @@ public:
 
     template <typename InitDataT>
     ConstSourceComponent addComponent(const ConstSourceComponentClass componentClass,
-                                      const bt2c::CStringView name, InitDataT& initData,
+                                      const bt2c::CStringView name, InitDataT&& initData,
                                       const OptionalBorrowedObject<ConstMapValue> params = {},
                                       const LoggingLevel loggingLevel = LoggingLevel::NONE) const
     {
@@ -87,7 +87,7 @@ public:
 
     template <typename InitDataT>
     ConstFilterComponent addComponent(const ConstFilterComponentClass componentClass,
-                                      const bt2c::CStringView name, InitDataT& initData,
+                                      const bt2c::CStringView name, InitDataT&& initData,
                                       const OptionalBorrowedObject<ConstMapValue> params = {},
                                       const LoggingLevel loggingLevel = LoggingLevel::NONE) const
     {
@@ -108,7 +108,7 @@ public:
 
     template <typename InitDataT>
     ConstSinkComponent addComponent(const ConstSinkComponentClass componentClass,
-                                    const bt2c::CStringView name, InitDataT& initData,
+                                    const bt2c::CStringView name, InitDataT&& initData,
                                     const OptionalBorrowedObject<ConstMapValue> params = {},
                                     const LoggingLevel loggingLevel = LoggingLevel::NONE) const
     {
This page took 0.025041 seconds and 4 git commands to generate.