]> git.tdb.fi Git - libs/datafile.git/commitdiff
Disable the templated constructor of Value if the source type is Value
authorMikko Rasa <tdb@tdb.fi>
Sun, 18 Dec 2022 10:59:32 +0000 (12:59 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sun, 18 Dec 2022 10:59:32 +0000 (12:59 +0200)
Microsoft's std::vector uses a T & (without const) for copying, which
resolves to the templated constructor instead of the copy constructor
unless the former is disabled for that signature.

source/value.h

index bcddd6ed3aebb579256cd0a11061a76312a4a95c..ba6118181260c1c92c2a53f8f885507914a4d759 100644 (file)
@@ -2,6 +2,7 @@
 #define MSP_DATAFILE_VALUE_H_
 
 #include <vector>
+#include <type_traits>
 #include <msp/core/attributes.h>
 #include <msp/core/meta.h>
 #include <msp/core/variant.h>
@@ -18,7 +19,7 @@ private:
 
 public:
        template<typename T>
-       Value(T &&d):
+       Value(T &&d, typename std::enable_if<!std::is_same<typename std::remove_reference<T>::type, Value>::value, int>::type = 0):
                sig(TypeInfo<T>::signature),
                data(static_cast<typename TypeInfo<T>::Store>(std::forward<T>(d)))
        { }