FAQ Database Discussion Community


Template overload resolution for operators inside an anonymous namespace

c++,templates,gcc,language-lawyer,argument-dependent-lookup
Short question: do operators have special template lookup rules for overload resolution with internal linkage or is the code at the bottom a template overload resolution bug for operators in GCC? The detail: instead of pasting a chunk of code I'll take you through my reasoning. Let's start with some...

why move swap_impl in boost::swap to a separate namespace?

c++,boost,argument-dependent-lookup
I am looking into boost::swap implementation: namespace boost_swap_impl { template<class T> BOOST_GPU_ENABLED void swap_impl(T& left, T& right) { using namespace std;//use std::swap if argument dependent lookup fails swap(left,right); } template<class T, std::size_t N> BOOST_GPU_ENABLED void swap_impl(T (& left)[N], T (& right)[N]) { for (std::size_t i = 0; i < N;...

c++ operator overloading and associated namespace

c++,namespaces,operator-overloading,clang,argument-dependent-lookup
The following simplified example compiles in gcc and Visual Studio, but fails in clang !? namespace N { struct A {}; template <typename T> double operator+ (T a, double d) {return d;} template <typename T> double operator+ (double d, T a) {return d;} } void test() { N::A a; double...

initializer_list and argument-dependent lookup

c++,c++11,initializer-list,argument-dependent-lookup
I'm trying to use an std::initializer_list as an argument in a function that uses argument-dependent lookup (ADL). But I don't get it to work and I don't understand why. The following is a minimal failing example: #include <initializer_list> #include <iostream> class Foo { public: inline friend void bar(std::initializer_list<Foo> v) {...

Getting constexpr functions resolved without creating parameter objects

c++,templates,c++11,constexpr,argument-dependent-lookup
Short version: If I have function like: constexpr bool has_some_property(Foo) { return true; } Is there any way to invoke the function without having to actually instantiate Foo? Say if Foo is not default constructible? Long winded version: Anthony Williams recently wrote an article detailing a set of free functions...

Possible ADL bug in Visual Studio 2013

c++,gcc,visual-studio-2013,argument-dependent-lookup
The following simplified code fails to compile under VS2013: #include <cmath> namespace mine { template <typename A> struct Base { double value() const { return static_cast<const A&>(*this).value(); } }; struct Derived : Base < Derived > { Derived(double x) : m_val(x) {} double value() const { return m_val; } double...