Mismatch overload problem

Why does s have the value false?


1
2
3
4
5
6
template<typename T> char test_have_range(decltype(&T::begin), decltype(&T::end));
template<typename T> short test_have_range(...);

constexpr bool s = sizeof(test_have_range<list<int>>(0,0)) == sizeof(char);

static_assert(s);



Regards,
Juan
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#ifndef DUTHOMHAS_IS_ITERABLE_HPP
#define DUTHOMHAS_IS_ITERABLE_HPP

// SFINAE check to see if class can be used with begin() and end()

// Copyright 2017 Michael Thomas Greer
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file ../../LICENSE_1_0.txt or copy at
//  http://www.boost.org/LICENSE_1_0.txt )

#include <iterator>
#include <type_traits>
#include <utility>

namespace duthomhas
{
  //-----------------------------------------------------------------------------------------------
  // is_iterable <T> ::value
  //-----------------------------------------------------------------------------------------------
  // The basis for this code was found at
  // https://stackoverflow.com/a/29634934/2706707
  //
  namespace is_iterable_internal
  {
    using std::begin;
    using std::end;
    
    template <typename T>
    class is_iterable
    {
      template <typename U>
      static constexpr auto is_iterable_impl( int ) 
        -> decltype(
             begin( std::declval <U&> () ) != end( std::declval <U&> () ),   // begin/end and operator !=
             void(),                                                         // Handle evil operator ,
             ++std::declval <decltype( begin( std::declval <U&> () ) )&> (), // operator ++
             void( *begin( std::declval <U&> () ) ),                         // operator*
             std::true_type {}
           )
      { return std::true_type {}; }
    
      template <typename U>
      static constexpr std::false_type is_iterable_impl(...)
      { return std::false_type {}; }
    
      typedef decltype( is_iterable_impl <T> ( 0 ) ) type;
      
    public:
      #if __cplusplus < 201402L
      enum : bool { value = type::value };
      #else
      static constexpr bool value = type::value;
      #endif
    };
  }
  
  template <typename T>
  using is_iterable = is_iterable_internal::is_iterable <T> ;
}

#endif 

Registered users can post here. Sign in or register to post.