I'm reading through C++ Template Metaprogramming and thought I was
understanding things pretty well until I tried to do exercise 2-0 which
wants you to make a add_const_ref<T> that returns T if it's already a
reference type, else return T const&. I include my floundering below
inline, which gets these errors in their current state. I'm really stuck.
g++ -ggdb test.cpp -o test
In file included from test.cpp:1:
add_const_ref.h:21: error: explicit specialization in non-namespace
scope ‘class mine::add_const_ref<T>’
add_const_ref.h:22: error: template parameters not used in partial
specialization:
add_const_ref.h:22: error: ‘T’
#if !defined ADD_CONST_REF
#define ADD_CONST_REF
#include <boost/type_traits/add_reference.hpp>
#include <boost/type_traits/is_reference.hpp>
namespace mine {
template <bool is_const_ref>struct acr_impl;
template<typename T>
class add_const_ref
{
bool static const is_const_ref=boost::is_reference<T>::value;
template<bool x>
struct acr_impl
{
typedef T type;
};
template<>
struct acr_impl<true>
{
typedef T type;
};
#if 0
template<>
struct acr_impl<false>
{
typedef boost::add_reference<T> type;
};
typedef acr_impl<is_const_ref>::type type;
#endif
};
};
#endif // ADD_CONST_REF