Skip to Main Content

DevOps, CI/CD and Automation

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

C++ partial specialization problem with templates differing only in namespace

kovalApr 27 2015 — edited May 7 2015

Solaris Studio 12.3 compiler fails with partial specialization for template classes with the same name in different namespaces.

namespace ns1 {

template<typename T> struct a {};

}

namespace ns2 {

template<typename T> struct a {};

}

template<typename T>

struct is_a { static const bool value = false; };

template<typename T>

struct is_a< ns1::a<T> > { static const bool value = true; };

#ifndef NO_NS2

template<typename T>

struct is_a< ns2::a<T> > { static const bool value = true; };

#endif

template<bool>

struct enable_if {};

template<>

struct enable_if<true> { typedef void type; };

template<typename T>

typename enable_if<is_a<T>::value>::type

fun(const T&)

{

}

void a()

{

    fun(ns1::a<int>());

    fun(ns2::a<char>());

}

Compiling above code gives errors:

Error: Could not find a match for fun<T>(ns1::a<int>) needed in a().

Error: Could not find a match for fun<T>(ns2::a<char>) needed in a().

What is more, compiling with -DNO_NS2 (so that specialization for ns2::a gets #ifdef'ed) produces no errors though there should be no match for fun<T>(ns2::a<char>)

I found this bug when trying to use Boost 1.57. In lexical_cast library, is_stdstring trait which fails because it has specializations for std::basic_string and boost::container::basic_string.

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 4 2015
Added on Apr 27 2015
4 comments
2,223 views