Add mp_value; enable mp_rename on value lists. Refs #53.

This commit is contained in:
Peter Dimov
2023-05-14 19:45:09 +03:00
parent 173e5d8098
commit 570acee866
7 changed files with 139 additions and 4 deletions

View File

@@ -123,6 +123,17 @@
# endif
#endif
// BOOST_MP11_HAS_TEMPLATE_AUTO
#if defined(__cpp_nontype_template_parameter_auto) && __cpp_nontype_template_parameter_auto >= 201606L
# define BOOST_MP11_HAS_TEMPLATE_AUTO
#endif
#if BOOST_MP11_WORKAROUND( BOOST_MP11_MSVC, < 1920 )
// mp_value<0> is bool, mp_value<-1L> is int, etc
# undef BOOST_MP11_HAS_TEMPLATE_AUTO
#endif
// BOOST_MP11_DEPRECATED(msg)
#if BOOST_MP11_WORKAROUND( BOOST_MP11_CLANG, < 304 )

View File

@@ -1,7 +1,7 @@
#ifndef BOOST_MP11_DETAIL_MP_RENAME_HPP_INCLUDED
#define BOOST_MP11_DETAIL_MP_RENAME_HPP_INCLUDED
// Copyright 2015-2021 Peter Dimov.
// Copyright 2015-2023 Peter Dimov.
//
// Distributed under the Boost Software License, Version 1.0.
//
@@ -9,6 +9,8 @@
// http://www.boost.org/LICENSE_1_0.txt
#include <boost/mp11/detail/mp_defer.hpp>
#include <boost/mp11/detail/mp_value.hpp>
#include <boost/mp11/detail/config.hpp>
namespace boost
{
@@ -19,21 +21,31 @@ namespace mp11
namespace detail
{
template<class A, template<class...> class B> struct mp_rename_impl
template<class L, template<class...> class B> struct mp_rename_impl
{
// An error "no type named 'type'" here means that the first argument to mp_rename is not a list
};
template<template<class...> class A, class... T, template<class...> class B> struct mp_rename_impl<A<T...>, B>: mp_defer<B, T...>
template<template<class...> class L, class... T, template<class...> class B> struct mp_rename_impl<L<T...>, B>: mp_defer<B, T...>
{
};
#if defined(BOOST_MP11_HAS_TEMPLATE_AUTO)
template<template<auto...> class L, auto... A, template<class...> class B> struct mp_rename_impl<L<A...>, B>: mp_defer<B, mp_value<A>...>
{
};
#endif
} // namespace detail
template<class A, template<class...> class B> using mp_rename = typename detail::mp_rename_impl<A, B>::type;
template<class L, template<class...> class B> using mp_rename = typename detail::mp_rename_impl<L, B>::type;
// mp_apply<F, L>
template<template<class...> class F, class L> using mp_apply = typename detail::mp_rename_impl<L, F>::type;
// mp_apply_q<Q, L>
template<class Q, class L> using mp_apply_q = typename detail::mp_rename_impl<L, Q::template fn>::type;
} // namespace mp11

View File

@@ -0,0 +1,25 @@
#ifndef BOOST_MP11_DETAIL_MP_VALUE_HPP_INCLUDED
#define BOOST_MP11_DETAIL_MP_VALUE_HPP_INCLUDED
// Copyright 2023 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/mp11/detail/config.hpp>
#include <type_traits>
#if defined(BOOST_MP11_HAS_TEMPLATE_AUTO)
namespace boost
{
namespace mp11
{
template<auto A> using mp_value = std::integral_constant<decltype(A), A>;
} // namespace mp11
} // namespace boost
#endif // #if defined(BOOST_MP11_HAS_TEMPLATE_AUTO)
#endif // #ifndef BOOST_MP11_DETAIL_MP_VALUE_HPP_INCLUDED

View File

@@ -9,6 +9,7 @@
// http://www.boost.org/LICENSE_1_0.txt
#include <boost/mp11/version.hpp>
#include <boost/mp11/detail/mp_value.hpp>
#include <type_traits>
#include <cstddef>