1
0
forked from boostorg/mp11

Make mp_at SFINAE-friendly

This commit is contained in:
Peter Dimov
2017-05-29 05:56:55 +03:00
parent c7923ca041
commit f6d92069a9
3 changed files with 42 additions and 2 deletions

View File

@ -325,8 +325,8 @@ template<class L, std::size_t I> struct mp_at_c_impl
} // namespace detail
template<class L, std::size_t I> using mp_at_c = typename detail::mp_at_c_impl<L, I>::type;
template<class L, class I> using mp_at = typename detail::mp_at_c_impl<L, std::size_t{ I::value }>::type;
template<class L, std::size_t I> using mp_at_c = typename mp_if_c<(I < mp_size<L>::value), detail::mp_at_c_impl<L, I>, void>::type;
template<class L, class I> using mp_at = mp_at_c<L, std::size_t{ I::value }>;
// mp_take(_c)<L, N>
namespace detail

View File

@ -48,6 +48,7 @@ run mp_product.cpp : : : $(REQ) ;
run mp_drop.cpp : : : $(REQ) ;
run mp_iota.cpp : : : $(REQ) ;
run mp_at.cpp : : : $(REQ) ;
run mp_at_sf.cpp : : : $(REQ) ;
run mp_take.cpp : : : $(REQ) ;
run mp_replace.cpp : : : $(REQ) ;
run mp_replace_if.cpp : : : $(REQ) ;

39
test/mp_at_sf.cpp Normal file
View File

@ -0,0 +1,39 @@
// Copyright 2015, 2017 Peter Dimov.
//
// Distributed under the Boost Software License, Version 1.0.
//
// See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt
#include <boost/mp11/utility.hpp>
#include <boost/mp11/algorithm.hpp>
#include <boost/core/lightweight_test_trait.hpp>
#include <type_traits>
using boost::mp11::mp_valid;
using boost::mp11::mp_at;
using boost::mp11::mp_size_t;
using boost::mp11::mp_list;
int main()
{
BOOST_TEST_TRAIT_FALSE((mp_valid<mp_at>));
BOOST_TEST_TRAIT_FALSE((mp_valid<mp_at, void>));
BOOST_TEST_TRAIT_FALSE((mp_valid<mp_at, void, void>));
BOOST_TEST_TRAIT_FALSE((mp_valid<mp_at, void, void, void>));
BOOST_TEST_TRAIT_FALSE((mp_valid<mp_at, void, mp_size_t<0>>));
BOOST_TEST_TRAIT_FALSE((mp_valid<mp_at, mp_list<>, mp_size_t<0>>));
BOOST_TEST_TRAIT_TRUE((mp_valid<mp_at, mp_list<void>, mp_size_t<0>>));
BOOST_TEST_TRAIT_FALSE((mp_valid<mp_at, mp_list<void>, mp_size_t<1>>));
BOOST_TEST_TRAIT_TRUE((mp_valid<mp_at, mp_list<void, void>, mp_size_t<0>>));
BOOST_TEST_TRAIT_TRUE((mp_valid<mp_at, mp_list<void, void>, mp_size_t<1>>));
BOOST_TEST_TRAIT_FALSE((mp_valid<mp_at, mp_list<void, void>, mp_size_t<2>>));
return boost::report_errors();
}