Preventing Implicit Conversion of Some Arguments to Member Template Functions

I currently have a member function defined as such:

template<typename T> bool updateParameter(const std::string& name, const T& data);

With overload for pointers.

template<typename T> bool updateParameter(const std::string& name, T* data);

I would like to use this function as such:

int test = 20;
updateParameter<int>("name", 0);
updateParameter<int>("Referenced parameter", &test);

Thus, I can have a parameter object that either owns the data that it represents, or points to an element that belongs to the user.

MSVC const 0 "name" , , . , const char [] std::string name. , MSVC GCC, , , , const T & T *

+4
1

V++. (char const[5] = > std::string const&).
: T const& -overload - Β§13.3.3.1.4/1:

(8.5.3) , - , , [...]

0 . Β§4.10

(2.13.2) 0 prvalue std::nullptr_t. ; . .

Β§13.3.3.1.1/3 , , :

enter image description here


V++, (, rextester V++).
- data . Β§ 13.3.3.2/3.2.6. updateParameter .

+2

Source: https://habr.com/ru/post/1599545/


All Articles