/*! * \file integralconstant.h * \brief Template meta-programming integral constant * * Copyright (C) 2018 Christos Choutouridis * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ #ifndef __utl_meta_integralconstant_h__ #define __utl_meta_integralconstant_h__ #include /*! * \ingroup meta * \defgroup integral * integral constant support header */ //! @{ namespace utl { namespace meta { /*! * Empty type * utl::meta's nil type is not pure nil. It's a recursive "de-referencable nil. * Each time someone applies ::type to it, he gets back nil_. This way we can prevent * a lot of compilation errors in a wrong meta:: handling. */ struct nil_ { using type = nil_; }; //! Type alias for \p _Tp::type. Used to extract return type of metafunctions template using type_ = typename _Tp::type; //! integral_constant //! An Integral Constant is a holder class for a compile-time value of an integral type. //! Every Integral Constant is also a null-ary Metafunction, returning itself. //! An integral constant object is implicitly convertible to the corresponding //! run-time value of the wrapped integral type //! @{ template struct integral_constant { using value_type = _Tp; using type = integral_constant<_Tp, _v>; constexpr operator value_type() const noexcept { return value; } constexpr value_type operator()() const noexcept { return value; } static constexpr _Tp value = _v; }; template constexpr _Tp integral_constant<_Tp, _v>::value; //! @} //! Wrappers for basic types //! @{ //! integral constant template using integral_c = integral_constant<_Tp, _v>; //! bool_ type: integral constant wrapper for bool template using bool_ = integral_c; using true_ = bool_; //!< The type used as a compile-time boolean with true value. using false_ = bool_; //!< The type used as a compile-time boolean with false value. //! int8_ type: integral constant wrapper for \c int8_t template using int8_ = integral_c; //! uint8_ type: integral constant wrapper for \c uint8_t template using uint8_ = integral_c; //! int16_ type: integral constant wrapper for \c int16_t template using int16_ = integral_c; //! uint16_ type: integral constant wrapper for \c uint16_t template using uint16_ = integral_c; //! int32_ type: integral constant wrapper for \c int32_t template using int32_ = integral_c; //! uint32_ type: integral constant wrapper for \c uint32_t template using uint32_ = integral_c; //! char_ type: integral constant wrapper for \c char template using char_ = integral_c; //! int_ type: integral constant wrapper for \c int template using int_ = integral_c; //! long_ type: integral constant wrapper for \c long template using long_ = integral_c; //! index_t_ type: integral constant wrapper for \c index_t a.k.a std::size_t template using index_t_ = integral_c; //! size_t_ type: integral constant wrapper for \c size_t a.k.a std::size_t template using size_t_ = integral_constant; //! Computes the size of the type \p _Tp. //! Complexity \f$ O(1) \f$. template using sizeof_ = size_t_; //! Computes the alignment required for any instance of the type \p _Tp. //! Complexity \f$ O(1) \f$. template using alignof_ = size_t_; //! @} //! The last position we can express for indexing using Npos = size_t_; }} //!@} #endif /* __utl_meta_integralconstant_h__ */