Okay so, I'm trying to implement this with boost. I (sort of) understand why all this works. But the compiler keeps spitting out an error when I try to implement the same thing with boosts's enable_if.
This worked with C++11 type_traits. Swapping to boost the compiler keeps spitting out this:
main.cpp:29:5: error: no matching function for call to 'get_param'
get_param<std::vector<int> >("int");
^~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:20:1: note: candidate template ignored: substitution failure [with T =
std::__1::vector<int, std::__1::allocator<int> >]: typename specifier
refers to non-type member 'value' in 'is_vector<std::__1::vector<int,
std::__1::allocator<int> >, bool>'
get_param(string const &path)
as the compiler said, "typename specifier refers to non-type member 'value".
You wrote typename is_int<T>::value which tells the compiled that 'value' is a nested type within is_int<T>, but it is, in fact, the name of a member object. Just remove the keyword "typename" in that expression (or in is_vector<T>::value, which is what the compiler diagnostic says it was trying to use)
See, that's what I thought, but removing typename gives me this response:
error: template argument for template type parameter must be a
type; did you forget 'typename'?
template <typename T> typename boost::enable_if<is_int<T>::value, T>::type
^
enable_if.hpp:35:19: note: template parameter
is declared here
template <class Cond, class T = void>
^
Why would it tell me a template type parameter must be a type, then?
EDIT: Resolved.
Apparently boost::enable_if checks a member variable named "value" internally, which makes this valid: boost::enable_if<is_int<T>, T>::type