explicit-specialization

Is it valid to do explicit template specialisation with auto return 'type' in C++14?

久未见 提交于 2019-12-05 09:06:22
Previous question . I repeat the code from the previous question to make this question self-contained. The code below compiles and does not issue any warnings if it is compiled using gcc 4.8.3. with -std=c++1y . However, it does issue warnings if compiled with -std=c++0x flag. In the context of the previous question it was stated that the code does not compile using gcc 4.9.0. Unfortunately, at present, I do not fully understand how auto is implemented. Thus, I would appreciate if anyone could answer the following questions: 1). Is the code below valid C++ with respect to the C++14 standard? 2

SFINAE: detect existence of a template function that requires explicit specialization

淺唱寂寞╮ 提交于 2019-12-05 02:57:06
As a follow-up to my previous question , I am trying to detect the existence of a template function that requires explicit specialization. My current working code detects non-template functions (thanks to DyP's help), provided they take at least one parameter so that dependent name lookup can be used: // switch to 0 to test the other case #define ENABLE_FOO_BAR 1 namespace foo { #if ENABLE_FOO_BAR int bar(int); #endif } namespace feature_test { namespace detail { using namespace foo; template<typename T> decltype(bar(std::declval<T>())) test(int); template<typename> void test(...); } static

Why won't “extern template” work with shared_ptr?

流过昼夜 提交于 2019-12-03 15:24:19
I had the (seemingly) bright idea of using extern template class std::shared_ptr<SomeWidelyUsedClass> in stdafx.h immediately after #include <memory> in order to prevent std::shared_ptr<SomeWidelyUsedClass> from being redundantly instantiated in hundreds of files, figuring I could place template class std::shared_ptr<SomeWidelyUsedClass> in a single .cpp in order to force a single instantiation and hopefully save on compile/link time. However, examination of the resulting .cod and .obj files shows that shared_ptr<SomeWidelyUsedClass> code is being created everywhere anyway. But if I use this

Explicit specialization of member function template in source file

放肆的年华 提交于 2019-11-30 09:11:41
I have a class with a member template function: // writer.h class Writer { public: ... template <typename T, typename V> void addField(const std::string& name, V v) { // write something } }; And in Writer's source file, I added explicit specializations for some_type : // writer.cpp template <> void Writer::addField<some_type, int>(const std::string& name, int v) { // specific some_type writing logic } This works... sometimes. Even if I definitely make sure that I have the right types: writer.addField<some_type>("name", static_cast<int>(some_value)); Sometimes the explicit specialization gets

What can and can't I specialize in the std namespace?

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-26 17:27:58
Users are allowed to add explicit specializations to the std namespace. However, there are a few templates that I am explicitly forbidden from specializing. What templates can and can't I specialize? Kerrek SB Quoting loosely from the standard: numeric_limits shall not be specialized for non-arithmetic standard types (e.g. complex<T> ) "[S]pecializations of shared_ptr shall be CopyConstructible, CopyAssignable, and LessThanComparable [and] convertible to bool ." "Specializations of weak_ptr shall be CopyConstructible and CopyAssignable." "[T]emplate specializations [of std::hash ] shall meet

What can and can&#39;t I specialize in the std namespace?

和自甴很熟 提交于 2019-11-26 06:06:07
问题 Users are allowed to add explicit specializations to the std namespace. However, there are a few templates that I am explicitly forbidden from specializing. What templates can and can\'t I specialize? 回答1: Quoting loosely from the standard: numeric_limits shall not be specialized for non-arithmetic standard types (e.g. complex<T> ) "[S]pecializations of shared_ptr shall be CopyConstructible, CopyAssignable, and LessThanComparable [and] convertible to bool ." "Specializations of weak_ptr shall