forked from boostorg/mp11
Add support for value lists to mp_front. Refs #53.
This commit is contained in:
@@ -1,13 +1,16 @@
|
|||||||
#ifndef BOOST_MP11_DETAIL_MP_FRONT_HPP_INCLUDED
|
#ifndef BOOST_MP11_DETAIL_MP_FRONT_HPP_INCLUDED
|
||||||
#define BOOST_MP11_DETAIL_MP_FRONT_HPP_INCLUDED
|
#define BOOST_MP11_DETAIL_MP_FRONT_HPP_INCLUDED
|
||||||
|
|
||||||
// Copyright 2015-2021 Peter Dimov.
|
// Copyright 2015-2023 Peter Dimov.
|
||||||
//
|
//
|
||||||
// Distributed under the Boost Software License, Version 1.0.
|
// Distributed under the Boost Software License, Version 1.0.
|
||||||
//
|
//
|
||||||
// See accompanying file LICENSE_1_0.txt or copy at
|
// See accompanying file LICENSE_1_0.txt or copy at
|
||||||
// http://www.boost.org/LICENSE_1_0.txt
|
// http://www.boost.org/LICENSE_1_0.txt
|
||||||
|
|
||||||
|
#include <boost/mp11/detail/mp_value.hpp>
|
||||||
|
#include <boost/mp11/detail/config.hpp>
|
||||||
|
|
||||||
namespace boost
|
namespace boost
|
||||||
{
|
{
|
||||||
namespace mp11
|
namespace mp11
|
||||||
@@ -28,6 +31,15 @@ template<template<class...> class L, class T1, class... T> struct mp_front_impl<
|
|||||||
using type = T1;
|
using type = T1;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#if defined(BOOST_MP11_HAS_TEMPLATE_AUTO)
|
||||||
|
|
||||||
|
template<template<auto...> class L, auto A1, auto... A> struct mp_front_impl<L<A1, A...>>
|
||||||
|
{
|
||||||
|
using type = mp_value<A1>;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
|
||||||
template<class L> using mp_front = typename detail::mp_front_impl<L>::type;
|
template<class L> using mp_front = typename detail::mp_front_impl<L>::type;
|
||||||
|
@@ -34,6 +34,7 @@ run mp_assign_2.cpp ;
|
|||||||
run mp_clear.cpp ;
|
run mp_clear.cpp ;
|
||||||
run mp_clear_2.cpp ;
|
run mp_clear_2.cpp ;
|
||||||
run mp_front.cpp ;
|
run mp_front.cpp ;
|
||||||
|
run mp_front_2.cpp ;
|
||||||
run mp_pop_front.cpp ;
|
run mp_pop_front.cpp ;
|
||||||
run mp_second.cpp ;
|
run mp_second.cpp ;
|
||||||
run mp_third.cpp ;
|
run mp_third.cpp ;
|
||||||
|
40
test/mp_front_2.cpp
Normal file
40
test/mp_front_2.cpp
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
// Copyright 2023 Peter Dimov
|
||||||
|
// Distributed under the Boost Software License, Version 1.0.
|
||||||
|
// https://www.boost.org/LICENSE_1_0.txt
|
||||||
|
|
||||||
|
#include <boost/mp11/list.hpp>
|
||||||
|
|
||||||
|
#if !defined(BOOST_MP11_HAS_TEMPLATE_AUTO)
|
||||||
|
|
||||||
|
#pragma message("Test skipped because BOOST_MP11_HAS_TEMPLATE_AUTO is not defined")
|
||||||
|
int main() {}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
#include <boost/mp11/integral.hpp>
|
||||||
|
#include <boost/core/lightweight_test_trait.hpp>
|
||||||
|
|
||||||
|
template<auto... A> struct L1 {};
|
||||||
|
template<int... I> struct L2 {};
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
using boost::mp11::mp_list_v;
|
||||||
|
using boost::mp11::mp_front;
|
||||||
|
using boost::mp11::mp_first;
|
||||||
|
using boost::mp11::mp_false;
|
||||||
|
using boost::mp11::mp_int;
|
||||||
|
|
||||||
|
BOOST_TEST_TRAIT_SAME(mp_front<mp_list_v<false>>, mp_false);
|
||||||
|
BOOST_TEST_TRAIT_SAME(mp_first<mp_list_v<false>>, mp_false);
|
||||||
|
|
||||||
|
BOOST_TEST_TRAIT_SAME(mp_front<L1<-1, true>>, mp_int<-1>);
|
||||||
|
BOOST_TEST_TRAIT_SAME(mp_first<L1<-1, true>>, mp_int<-1>);
|
||||||
|
|
||||||
|
BOOST_TEST_TRAIT_SAME(mp_front<L2<0, 1>>, mp_int<0>);
|
||||||
|
BOOST_TEST_TRAIT_SAME(mp_first<L2<0, 1>>, mp_int<0>);
|
||||||
|
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
Reference in New Issue
Block a user