Skip to content

Commit

Permalink
Improved begin/end check to include strict type checking.
Browse files Browse the repository at this point in the history
  • Loading branch information
louisdx committed Aug 20, 2011
1 parent f7a498e commit d9132f5
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion prettyprint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace pretty_print
// SFINAE type trait to detect whether "T::const_iterator T::begin/end() const" exist.

template <typename T>
struct has_begin_end
struct has_begin_end_OLD
{
struct Dummy { typedef void const_iterator; };
typedef typename std::conditional<has_const_iterator<T>::value, T, Dummy>::type TType;
Expand All @@ -60,6 +60,25 @@ namespace pretty_print
static bool const end_value = sizeof(g<Derived>(0)) == 2;
};

template <typename T>
struct has_begin_end
{
template<typename C> static char (&f(typename std::enable_if<
std::is_same<decltype(static_cast<typename C::const_iterator (C::*)() const>(&C::begin)),
typename C::const_iterator(C::*)() const>::value, void>::type*))[1];

template<typename C> static char (&f(...))[2];

template<typename C> static char (&g(typename std::enable_if<
std::is_same<decltype(static_cast<typename C::const_iterator (C::*)() const>(&C::end)),
typename C::const_iterator(C::*)() const>::value, void>::type*))[1];

template<typename C> static char (&g(...))[2];

static bool const beg_value = sizeof(f<T>(0)) == 1;
static bool const end_value = sizeof(g<T>(0)) == 1;
};

// Basic is_container template; specialize to derive from std::true_type for all desired container types

template<typename T> struct is_container : public ::std::integral_constant<bool,
Expand Down

0 comments on commit d9132f5

Please sign in to comment.