typetraits

What kind of “Traits” are used/defined in the C++0x Standard

拟墨画扇 提交于 2021-02-05 20:01:12
问题 A trait in C++ encapsulates a family of operations that allow an Algorithm or Data Structure to operator with that type with which it is instantiated. char_traits are an example for grouping string - and file-required functions. But not all traits have "trait" in their name, right? numeric_limits comes to mind. Is this a "Trait", too? Even without the name "trait" in it? So, are there other Templates that could/should be considered a "Trait"? Besides the examples I found: allocator_traits how

What kind of “Traits” are used/defined in the C++0x Standard

◇◆丶佛笑我妖孽 提交于 2021-02-05 20:00:37
问题 A trait in C++ encapsulates a family of operations that allow an Algorithm or Data Structure to operator with that type with which it is instantiated. char_traits are an example for grouping string - and file-required functions. But not all traits have "trait" in their name, right? numeric_limits comes to mind. Is this a "Trait", too? Even without the name "trait" in it? So, are there other Templates that could/should be considered a "Trait"? Besides the examples I found: allocator_traits how

Adding a const qualifier to a member function

偶尔善良 提交于 2021-01-27 05:39:46
问题 I am currently writing an interface class that should provide access to to internal elements of a complex structure as const or non-const references. The idea is that some modules are granted const access and some modules are granted full access. I have used the 'type_traits' 'std::add_const' to conditionally qualify the return type of the internal member functions, unfortunately I cannot think of a way of conditionally qualifiying the member functions as const or non-const. Is this even

Adding a const qualifier to a member function

白昼怎懂夜的黑 提交于 2021-01-27 05:39:40
问题 I am currently writing an interface class that should provide access to to internal elements of a complex structure as const or non-const references. The idea is that some modules are granted const access and some modules are granted full access. I have used the 'type_traits' 'std::add_const' to conditionally qualify the return type of the internal member functions, unfortunately I cannot think of a way of conditionally qualifiying the member functions as const or non-const. Is this even

std::enable_if to filter out the argument with the type of char*

一笑奈何 提交于 2021-01-07 01:27:21
问题 Why char* pstr="hello"; pushArg(pstr); still invoke such template? You see there is &&(!std::is_same<char, typename std::remove_cv_t<std::remove_pointer_t<T>>>::value) already. template <typename T, typename std::enable_if<(!std::is_same<lua_CFunction, T*>::value) && std::is_pointer<T>::value && (!std::is_same<std::string*, T>::value) && (!std::is_same<char, typename std::remove_cv<std::remove_pointer<T>>>::value) && (!std::is_same<unsigned char, typename std::remove_cv<std::remove_pointer<T>

What do we need std::as_const() for?

你离开我真会死。 提交于 2020-12-29 08:52:30
问题 C++11 has given us std::add_const; with C++17, we have a new structure - std::as_const(). The former just tacks a const before the type you provide it with. The second one is a proper (template of a) function, not type trait, which seems to do the same - except for when the type is an rvalue-reference, in which case it cannot be used. I don't quite understand the motivation for providing std::as_const() . Why do we need it in addition to std::add_const ? 回答1: "Need" is a strong word... std:

What do we need std::as_const() for?

让人想犯罪 __ 提交于 2020-12-29 08:52:23
问题 C++11 has given us std::add_const; with C++17, we have a new structure - std::as_const(). The former just tacks a const before the type you provide it with. The second one is a proper (template of a) function, not type trait, which seems to do the same - except for when the type is an rvalue-reference, in which case it cannot be used. I don't quite understand the motivation for providing std::as_const() . Why do we need it in addition to std::add_const ? 回答1: "Need" is a strong word... std:

What do we need std::as_const() for?

情到浓时终转凉″ 提交于 2020-12-29 08:52:07
问题 C++11 has given us std::add_const; with C++17, we have a new structure - std::as_const(). The former just tacks a const before the type you provide it with. The second one is a proper (template of a) function, not type trait, which seems to do the same - except for when the type is an rvalue-reference, in which case it cannot be used. I don't quite understand the motivation for providing std::as_const() . Why do we need it in addition to std::add_const ? 回答1: "Need" is a strong word... std:

What do we need std::as_const() for?

吃可爱长大的小学妹 提交于 2020-12-29 08:52:01
问题 C++11 has given us std::add_const; with C++17, we have a new structure - std::as_const(). The former just tacks a const before the type you provide it with. The second one is a proper (template of a) function, not type trait, which seems to do the same - except for when the type is an rvalue-reference, in which case it cannot be used. I don't quite understand the motivation for providing std::as_const() . Why do we need it in addition to std::add_const ? 回答1: "Need" is a strong word... std: