forked from boostorg/mp11
Add mp_sort_q
This commit is contained in:
@ -472,6 +472,12 @@ using L1 = mp_list<std::ratio<1,2>, std::ratio<1,4>>;
|
|||||||
using R1 = mp_sort<L1, std::ratio_less>; // mp_list<ratio<1,4>, ratio<1,2>>
|
using R1 = mp_sort<L1, std::ratio_less>; // mp_list<ratio<1,4>, ratio<1,2>>
|
||||||
----
|
----
|
||||||
|
|
||||||
|
## mp_sort_q<L, Q>
|
||||||
|
|
||||||
|
template<class L, class Q> using mp_sort_q = mp_sort<L, Q::template fn>;
|
||||||
|
|
||||||
|
As `mp_sort`, but takes a quoted metafunction.
|
||||||
|
|
||||||
## mp_nth_element_c<L, I, P>
|
## mp_nth_element_c<L, I, P>
|
||||||
|
|
||||||
template<class L, std::size_t I, template<class...> class P> using mp_nth_element_c = /*...*/;
|
template<class L, std::size_t I, template<class...> class P> using mp_nth_element_c = /*...*/;
|
||||||
|
@ -516,6 +516,7 @@ template<template<class...> class L, class T1, class... T, template<class...> cl
|
|||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
|
||||||
template<class L, template<class...> class P> using mp_sort = typename detail::mp_sort_impl<L, P>::type;
|
template<class L, template<class...> class P> using mp_sort = typename detail::mp_sort_impl<L, P>::type;
|
||||||
|
template<class L, class Q> using mp_sort_q = mp_sort<L, Q::template fn>;
|
||||||
|
|
||||||
// mp_nth_element(_c)<L, I, P>
|
// mp_nth_element(_c)<L, I, P>
|
||||||
namespace detail
|
namespace detail
|
||||||
|
@ -64,6 +64,7 @@ run mp_remove_if_q.cpp ;
|
|||||||
run mp_partition.cpp ;
|
run mp_partition.cpp ;
|
||||||
run mp_partition_q.cpp ;
|
run mp_partition_q.cpp ;
|
||||||
run mp_sort.cpp ;
|
run mp_sort.cpp ;
|
||||||
|
run mp_sort_q.cpp ;
|
||||||
run mp_find.cpp ;
|
run mp_find.cpp ;
|
||||||
run mp_find_if.cpp ;
|
run mp_find_if.cpp ;
|
||||||
run mp_reverse.cpp ;
|
run mp_reverse.cpp ;
|
||||||
|
58
test/mp_sort_q.cpp
Normal file
58
test/mp_sort_q.cpp
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
|
||||||
|
// 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/algorithm.hpp>
|
||||||
|
#include <boost/mp11/list.hpp>
|
||||||
|
#include <boost/mp11/integral.hpp>
|
||||||
|
#include <boost/core/lightweight_test_trait.hpp>
|
||||||
|
#include <type_traits>
|
||||||
|
#include <tuple>
|
||||||
|
|
||||||
|
using boost::mp11::mp_bool;
|
||||||
|
|
||||||
|
struct Q_sizeof_less
|
||||||
|
{
|
||||||
|
template<class T, class U> using fn = mp_bool<(sizeof(T) < sizeof(U))>;
|
||||||
|
};
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
using boost::mp11::mp_list;
|
||||||
|
using boost::mp11::mp_sort_q;
|
||||||
|
|
||||||
|
{
|
||||||
|
using L1 = mp_list<>;
|
||||||
|
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_sort_q<L1, Q_sizeof_less>, L1>));
|
||||||
|
|
||||||
|
using L2 = mp_list<char[2], char[4], char[3], char[1]>;
|
||||||
|
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_sort_q<L2, Q_sizeof_less>, mp_list<char[1], char[2], char[3], char[4]>>));
|
||||||
|
|
||||||
|
using L3 = mp_list<char[2], char[4], char[2], char[3], char[1], char[2], char[1]>;
|
||||||
|
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_sort_q<L3, Q_sizeof_less>, mp_list<char[1], char[1], char[2], char[2], char[2], char[3], char[4]>>));
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
using L1 = std::tuple<>;
|
||||||
|
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_sort_q<L1, Q_sizeof_less>, L1>));
|
||||||
|
|
||||||
|
using L2 = std::tuple<char[2], char[4], char[3], char[1]>;
|
||||||
|
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_sort_q<L2, Q_sizeof_less>, std::tuple<char[1], char[2], char[3], char[4]>>));
|
||||||
|
|
||||||
|
using L3 = std::tuple<char[2], char[4], char[2], char[3], char[1], char[2], char[1]>;
|
||||||
|
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_sort_q<L3, Q_sizeof_less>, std::tuple<char[1], char[1], char[2], char[2], char[2], char[3], char[4]>>));
|
||||||
|
}
|
||||||
|
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
Reference in New Issue
Block a user