diff --git a/coord/traits.hpp b/coord/traits.hpp index 2619bbd3..0d80cf2e 100644 --- a/coord/traits.hpp +++ b/coord/traits.hpp @@ -3,11 +3,10 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * - * Copyright 2012-2017 Danny Robson + * Copyright 2012-2019 Danny Robson */ -#ifndef CRUFT_UTIL_COORD_TRAITS_HPP -#define CRUFT_UTIL_COORD_TRAITS_HPP +#pragma once #include "fwd.hpp" @@ -197,12 +196,14 @@ namespace cruft { template struct arity {}; + //------------------------------------------------------------------------- template struct arity,void> > :std::integral_constant { }; + //------------------------------------------------------------------------- template struct arity< T,std::enable_if_t,void> @@ -210,9 +211,46 @@ namespace cruft { { }; - /////////////////////////////////////////////////////////////////////////// + //------------------------------------------------------------------------- template constexpr auto arity_v = arity::value; + + + /////////////////////////////////////////////////////////////////////////// + template struct value_trait {}; + + + //------------------------------------------------------------------------- + template + struct value_trait> + { using value_type = T; }; + + + //------------------------------------------------------------------------- + template + using value_trait_t = typename value_trait::value_type; } -#endif + +#include "../types/description.hpp" + +namespace cruft::types { + template + struct arity_trait< + CoordT, + std::enable_if_t< + ::cruft::is_coord_v + > + > : public ::cruft::arity { }; + + + template + struct category_traits< + CoordT, + std::enable_if_t< + ::cruft::is_coord_v + > + > : public category_traits< + ::cruft::value_trait_t + > { }; +} diff --git a/strongdef.hpp b/strongdef.hpp index 17db6329..e3eb2ace 100644 --- a/strongdef.hpp +++ b/strongdef.hpp @@ -130,3 +130,22 @@ static auto indices (ContainerT const &obj) return view {obj}; } + + +#include "types/description.hpp" +namespace cruft::types { + template + struct arity_trait< + ::cruft::strongdef::index + > : + arity_trait + { ; }; + + + template + struct category_traits< + ::cruft::strongdef::index + > : + public category_traits + {}; +} diff --git a/types/description.hpp b/types/description.hpp index f925d9eb..7292332d 100644 --- a/types/description.hpp +++ b/types/description.hpp @@ -10,7 +10,7 @@ #include "../std.hpp" #include "../types.hpp" -#include "../debug.hpp" +#include "../debug/panic.hpp" #include #include @@ -43,6 +43,17 @@ namespace cruft::types { > { }; + //------------------------------------------------------------------------- + // Punt the handling of any enum to the underlying type. + template + struct arity_trait< + EnumT, + std::enable_if_t> + > : public arity_trait< + std::underlying_type_t + > { }; + + //------------------------------------------------------------------------- template constexpr auto arity_v = arity_trait::value; @@ -99,7 +110,7 @@ namespace cruft::types { //------------------------------------------------------------------------- - template + template struct category_traits; template <> struct category_traits : public std::integral_constant {}; @@ -117,6 +128,17 @@ namespace cruft::types { template <> struct category_traits : public std::integral_constant {}; + + template + struct category_traits< + EnumT, + std::enable_if_t< + std::is_enum_v + > + > : public category_traits> + { }; + + template constexpr auto category_traits_v = category_traits::value;