Skip to content

change contiguous to a class

Currently implemented as a number of global functions, but a templated class function would be more flexible. Eg,

//- Default definition: (integral | floating-point) are contiguous
template<class T>
struct contiguous
:
    std::integral_constant
    <
        bool,
        std::is_integral<T>::value || std::is_floating_point<T>::value
    >
{};


//- FixedList of (integral | floating-point) is contiguous
template<class T, unsigned N>
struct contiguous<FixedList<T, N>>
:
    std::integral_constant
    <
        bool,
        std::is_integral<T>::value || std::is_floating_point<T>::value
    >
{};

These definitions work for any size FixedList and thus eliminate most of contiguous.H. Template specializations for the function definition aren't really possible.

Pros:

  • usable in constexpr, at compile-time and static_assert

Cons:

  • user code that is currently overloading contiguous needs to specify it different.

      template<> inline bool contiguous<someType>() { return true; }
      template<> struct contiguous<someType> : std::true_type {};
Edited by Mark OLESEN