1
0
forked from boostorg/mp11

Merge branch 'develop'

This commit is contained in:
Peter Dimov
2015-06-21 19:59:43 +03:00
28 changed files with 1635 additions and 0 deletions

96
.gitattributes vendored Normal file
View File

@@ -0,0 +1,96 @@
* text=auto !eol svneol=native#text/plain
*.gitattributes text svneol=native#text/plain
# Scriptish formats
*.bat text svneol=native#text/plain
*.bsh text svneol=native#text/x-beanshell
*.cgi text svneol=native#text/plain
*.cmd text svneol=native#text/plain
*.js text svneol=native#text/javascript
*.php text svneol=native#text/x-php
*.pl text svneol=native#text/x-perl
*.pm text svneol=native#text/x-perl
*.py text svneol=native#text/x-python
*.sh eol=lf svneol=LF#text/x-sh
configure eol=lf svneol=LF#text/x-sh
# Image formats
*.bmp binary svneol=unset#image/bmp
*.gif binary svneol=unset#image/gif
*.ico binary svneol=unset#image/ico
*.jpeg binary svneol=unset#image/jpeg
*.jpg binary svneol=unset#image/jpeg
*.png binary svneol=unset#image/png
*.tif binary svneol=unset#image/tiff
*.tiff binary svneol=unset#image/tiff
*.svg text svneol=native#image/svg%2Bxml
# Data formats
*.pdf binary svneol=unset#application/pdf
*.avi binary svneol=unset#video/avi
*.doc binary svneol=unset#application/msword
*.dsp text svneol=crlf#text/plain
*.dsw text svneol=crlf#text/plain
*.eps binary svneol=unset#application/postscript
*.gz binary svneol=unset#application/gzip
*.mov binary svneol=unset#video/quicktime
*.mp3 binary svneol=unset#audio/mpeg
*.ppt binary svneol=unset#application/vnd.ms-powerpoint
*.ps binary svneol=unset#application/postscript
*.psd binary svneol=unset#application/photoshop
*.rdf binary svneol=unset#text/rdf
*.rss text svneol=unset#text/xml
*.rtf binary svneol=unset#text/rtf
*.sln text svneol=native#text/plain
*.swf binary svneol=unset#application/x-shockwave-flash
*.tgz binary svneol=unset#application/gzip
*.vcproj text svneol=native#text/xml
*.vcxproj text svneol=native#text/xml
*.vsprops text svneol=native#text/xml
*.wav binary svneol=unset#audio/wav
*.xls binary svneol=unset#application/vnd.ms-excel
*.zip binary svneol=unset#application/zip
# Text formats
.htaccess text svneol=native#text/plain
*.bbk text svneol=native#text/xml
*.cmake text svneol=native#text/plain
*.css text svneol=native#text/css
*.dtd text svneol=native#text/xml
*.htm text svneol=native#text/html
*.html text svneol=native#text/html
*.ini text svneol=native#text/plain
*.log text svneol=native#text/plain
*.mak text svneol=native#text/plain
*.qbk text svneol=native#text/plain
*.rst text svneol=native#text/plain
*.sql text svneol=native#text/x-sql
*.txt text svneol=native#text/plain
*.xhtml text svneol=native#text/xhtml%2Bxml
*.xml text svneol=native#text/xml
*.xsd text svneol=native#text/xml
*.xsl text svneol=native#text/xml
*.xslt text svneol=native#text/xml
*.xul text svneol=native#text/xul
*.yml text svneol=native#text/plain
boost-no-inspect text svneol=native#text/plain
CHANGES text svneol=native#text/plain
COPYING text svneol=native#text/plain
INSTALL text svneol=native#text/plain
Jamfile text svneol=native#text/plain
Jamroot text svneol=native#text/plain
Jamfile.v2 text svneol=native#text/plain
Jamrules text svneol=native#text/plain
Makefile* text svneol=native#text/plain
README text svneol=native#text/plain
TODO text svneol=native#text/plain
# Code formats
*.c text svneol=native#text/plain
*.cpp text svneol=native#text/plain
*.h text svneol=native#text/plain
*.hpp text svneol=native#text/plain
*.ipp text svneol=native#text/plain
*.tpp text svneol=native#text/plain
*.jam text svneol=native#text/plain
*.java text svneol=native#text/plain

View File

@@ -1,2 +1,4 @@
# mp11
Simple C++11 metaprogramming library
For background, please see the article ["Simple C++11 metaprogramming"](http://pdimov.com/cpp2/simple_cxx11_metaprogramming.html)

15
include/boost/mp11.hpp Normal file
View File

@@ -0,0 +1,15 @@
#ifndef BOOST_MP11_HPP_INCLUDED
#define BOOST_MP11_HPP_INCLUDED
// Copyright 2015 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/list.hpp>
#include <boost/mp11/integral.hpp>
#include <boost/mp11/utility.hpp>
#endif // #ifndef BOOST_MP11_HPP_INCLUDED

View File

@@ -0,0 +1,68 @@
#ifndef BOOST_MP11_DETAIL_MP_PLUS_HPP_INCLUDED
#define BOOST_MP11_DETAIL_MP_PLUS_HPP_INCLUDED
// Copyright 2015 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/config.hpp>
#include <type_traits>
namespace boost
{
// mp_plus
namespace detail
{
template<class... T> struct mp_plus_impl;
#if defined( BOOST_NO_CXX11_CONSTEXPR )
template<> struct mp_plus_impl<>
{
using type = std::integral_constant<int, 0>;
};
template<class T1, class... T> struct mp_plus_impl<T1, T...>
{
static const/*expr*/ auto _v = T1::value + mp_plus<T...>::value;
using type = std::integral_constant< typename std::remove_const<decltype(_v)>::type, _v >;
};
template<class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8, class T9, class T10, class... T> struct mp_plus_impl<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T...>
{
static const/*expr*/ auto _v = T1::value + T2::value + T3::value + T4::value + T5::value + T6::value + T7::value + T8::value + T9::value + T10::value + mp_plus<T...>::value;
using type = std::integral_constant< typename std::remove_const<decltype(_v)>::type, _v >;
};
#else
constexpr int cx_plus()
{
return 0;
}
template<class T1, class... T> constexpr auto cx_plus( T1 t1, T... t ) -> decltype( t1 + cx_plus( t... ) )
{
return t1 + cx_plus( t... );
}
template<class... T> struct mp_plus_impl
{
static constexpr auto _v = cx_plus( T::value... );
using type = std::integral_constant< typename std::remove_const<decltype(_v)>::type, _v >;
};
#endif
} // namespace detail
template<class... T> using mp_plus = typename detail::mp_plus_impl<T...>::type;
} // namespace boost
#endif // #ifndef BOOST_MP11_DETAIL_MP_PLUS_HPP_INCLUDED

View File

@@ -0,0 +1,34 @@
#ifndef BOOST_MP11_INTEGRAL_HPP_INCLUDED
#define BOOST_MP11_INTEGRAL_HPP_INCLUDED
// Copyright 2015 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 <type_traits>
#include <cstddef>
namespace boost
{
// mp_bool
template<bool B> using mp_bool = std::integral_constant<bool, B>;
using mp_true = mp_bool<true>;
using mp_false = mp_bool<false>;
// mp_to_bool
template<class T> using mp_to_bool = mp_bool<static_cast<bool>( T::value )>;
// mp_int
template<int I> using mp_int = std::integral_constant<int, I>;
// mp_size_t
template<std::size_t N> using mp_size_t = std::integral_constant<std::size_t, N>;
} // namespace boost
#endif // #ifndef BOOST_MP11_INTEGRAL_HPP_INCLUDED

346
include/boost/mp11/list.hpp Normal file
View File

@@ -0,0 +1,346 @@
#ifndef BOOST_MP11_LIST_HPP_INCLUDED
#define BOOST_MP11_LIST_HPP_INCLUDED
// Copyright 2015 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/integral.hpp>
#include <boost/mp11/detail/mp_plus.hpp>
#include <boost/config.hpp>
#include <boost/detail/workaround.hpp>
#include <type_traits>
namespace boost
{
// mp_list<T...>
template<class... T> struct mp_list
{
};
// mp_size<L>
namespace detail
{
template<class L> struct mp_size_impl;
template<template<class...> class L, class... T> struct mp_size_impl<L<T...>>
{
using type = mp_size_t<sizeof...(T)>;
};
} // namespace detail
template<class L> using mp_size = typename detail::mp_size_impl<L>::type;
// mp_empty<L>
template<class L> using mp_empty = mp_bool< mp_size<L>::value == 0 >;
// mp_front<L>
namespace detail
{
template<class L> struct mp_front_impl;
template<template<class...> class L, class T1, class... T> struct mp_front_impl<L<T1, T...>>
{
using type = T1;
};
} // namespace detail
template<class L> using mp_front = typename detail::mp_front_impl<L>::type;
// mp_pop_front<L>
namespace detail
{
template<class L> struct mp_pop_front_impl;
template<template<class...> class L, class T1, class... T> struct mp_pop_front_impl<L<T1, T...>>
{
using type = L<T...>;
};
} // namespace detail
template<class L> using mp_pop_front = typename detail::mp_pop_front_impl<L>::type;
// mp_first<L>
template<class L> using mp_first = mp_front<L>;
// mp_rest<L>
template<class L> using mp_rest = mp_pop_front<L>;
// mp_second<L>
namespace detail
{
template<class L> struct mp_second_impl;
template<template<class...> class L, class T1, class T2, class... T> struct mp_second_impl<L<T1, T2, T...>>
{
using type = T2;
};
} // namespace detail
template<class L> using mp_second = typename detail::mp_second_impl<L>::type;
// mp_third<L>
namespace detail
{
template<class L> struct mp_third_impl;
template<template<class...> class L, class T1, class T2, class T3, class... T> struct mp_third_impl<L<T1, T2, T3, T...>>
{
using type = T3;
};
} // namespace detail
template<class L> using mp_third = typename detail::mp_third_impl<L>::type;
// mp_push_front<L, T...>
namespace detail
{
template<class L, class... T> struct mp_push_front_impl;
template<template<class...> class L, class... U, class... T> struct mp_push_front_impl<L<U...>, T...>
{
using type = L<T..., U...>;
};
} // namespace detail
template<class L, class... T> using mp_push_front = typename detail::mp_push_front_impl<L, T...>::type;
// mp_push_back<L, T...>
namespace detail
{
template<class L, class... T> struct mp_push_back_impl;
template<template<class...> class L, class... U, class... T> struct mp_push_back_impl<L<U...>, T...>
{
using type = L<U..., T...>;
};
} // namespace detail
template<class L, class... T> using mp_push_back = typename detail::mp_push_back_impl<L, T...>::type;
// mp_rename<L, B>
namespace detail
{
template<class A, template<class...> class B> struct mp_rename_impl;
template<template<class...> class A, class... T, template<class...> class B> struct mp_rename_impl<A<T...>, B>
{
using type = B<T...>;
};
} // namespace detail
template<class A, template<class...> class B> using mp_rename = typename detail::mp_rename_impl<A, B>::type;
// mp_append<L...>
namespace detail
{
template<class... L> struct mp_append_impl;
template<> struct mp_append_impl<>
{
using type = mp_list<>;
};
template<template<class...> class L, class... T> struct mp_append_impl<L<T...>>
{
using type = L<T...>;
};
template<template<class...> class L1, class... T1, template<class...> class L2, class... T2, class... Lr> struct mp_append_impl<L1<T1...>, L2<T2...>, Lr...>
{
using type = typename mp_append_impl<L1<T1..., T2...>, Lr...>::type;
};
} // namespace detail
template<class... L> using mp_append = typename detail::mp_append_impl<L...>::type;
// mp_assign<L1, L2>
namespace detail
{
template<class L1, class L2> struct mp_assign_impl;
template<template<class...> class L1, class... T, template<class...> class L2, class... U> struct mp_assign_impl<L1<T...>, L2<U...>>
{
using type = L1<U...>;
};
} // namespace detail
template<class L1, class L2> using mp_assign = typename detail::mp_assign_impl<L1, L2>::type;
// mp_clear<L>
template<class L> using mp_clear = mp_assign<L, mp_list<>>;
// mp_transform<F, L...>
namespace detail
{
template<template<class...> class F, class... L> struct mp_transform_impl;
template<template<class...> class F, class... L> using mp_transform = typename mp_transform_impl<F, L...>::type;
template<template<class...> class F, template<class...> class L, class... T> struct mp_transform_impl<F, L<T...>>
{
using type = L<F<T>...>;
};
template<template<class...> class F, template<class...> class L1, class... T1, template<class...> class L2, class... T2> struct mp_transform_impl<F, L1<T1...>, L2<T2...>>
{
static_assert( sizeof...(T1) == sizeof...(T2), "The arguments of mp_transform should be of the same size" );
using type = L1<F<T1,T2>...>;
};
template<template<class...> class F, template<class...> class L1, class... T1, template<class...> class L2, class... T2, template<class...> class L3, class... T3> struct mp_transform_impl<F, L1<T1...>, L2<T2...>, L3<T3...>>
{
static_assert( sizeof...(T1) == sizeof...(T2) && sizeof...(T1) == sizeof...(T3), "The arguments of mp_transform should be of the same size" );
using type = L1<F<T1,T2,T3>...>;
};
} // namespace detail
template<template<class...> class F, class... L> using mp_transform = typename detail::mp_transform_impl<F, L...>::type;
// mp_fill<L, V>
namespace detail
{
template<class L, class V> struct mp_fill_impl;
template<template<class...> class L, class... T, class V> struct mp_fill_impl<L<T...>, V>
{
#if defined( BOOST_MSVC ) && BOOST_WORKAROUND( BOOST_MSVC, <= 1800 )
template<class...> struct _f { using type = V; };
using type = L<typename _f<T>::type...>;
#else
template<class...> using _f = V;
using type = L<_f<T>...>;
#endif
};
} // namespace detail
template<class L, class V> using mp_fill = typename detail::mp_fill_impl<L, V>::type;
// mp_count<L, V>
namespace detail
{
template<class L, class V> struct mp_count_impl;
template<template<class...> class L, class... T, class V> struct mp_count_impl<L<T...>, V>
{
using type = mp_plus<std::is_same<T, V>...>;
};
} // namespace detail
template<class L, class V> using mp_count = typename detail::mp_count_impl<L, V>::type;
// mp_count_if<L, P>
namespace detail
{
template<class L, template<class...> class P> struct mp_count_if_impl;
template<template<class...> class L, class... T, template<class...> class P> struct mp_count_if_impl<L<T...>, P>
{
#if defined( BOOST_MSVC ) && BOOST_WORKAROUND( BOOST_MSVC, <= 1800 )
template<class T> struct _f { using type = mp_to_bool<P<T>>; };
using type = mp_plus<typename _f<T>::type...>;
#else
using type = mp_plus<mp_to_bool<P<T>>...>;
#endif
};
} // namespace detail
template<class L, template<class...> class P> using mp_count_if = typename detail::mp_count_if_impl<L, P>::type;
// mp_contains<L, V>
template<class L, class V> using mp_contains = mp_to_bool<mp_count<L, V>>;
// mp_repeat(_c)<L, N>
namespace detail
{
template<class L, std::size_t N> struct mp_repeat_c_impl
{
using _l1 = typename mp_repeat_c_impl<L, N/2>::type;
using _l2 = typename mp_repeat_c_impl<L, N%2>::type;
using type = mp_append<_l1, _l1, _l2>;
};
template<class L> struct mp_repeat_c_impl<L, 0>
{
using type = mp_clear<L>;
};
template<class L> struct mp_repeat_c_impl<L, 1>
{
using type = L;
};
template<class L, class N> struct mp_repeat_impl
{
static_assert( N::value >= 0, "mp_repeat<L, N>: N must not be negative" );
using type = typename mp_repeat_c_impl<L, N::value>::type;
};
} // namespace detail
template<class L, std::size_t N> using mp_repeat_c = typename detail::mp_repeat_c_impl<L, N>::type;
template<class L, class N> using mp_repeat = typename detail::mp_repeat_impl<L, N>::type;
// mp_drop<L, N>
// mp_take<L, N>
// mp_find<L, V>
// mp_find_if<L, P>
// mp_find_index<L, V>
// mp_find_index_if<L, P>
// mp_reverse<L>
// mp_copy_if<L, P>
// mp_remove_if<L, P>
// mp_product<L...>?
// mp_fold<L, V, F>
// mp_reverse_fold<L, V, F>
// mp_replace<L, V1, V2>?
// mp_replace_if<L, P, V2>?
// mp_partition<L, P>
// mp_sort<L>
} // namespace boost
#endif // #ifndef BOOST_MP11_LIST_HPP_INCLUDED

View File

@@ -0,0 +1,59 @@
#ifndef BOOST_MP11_UTILITY_HPP_INCLUDED
#define BOOST_MP11_UTILITY_HPP_INCLUDED
// Copyright 2015 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
namespace boost
{
// mp_identity
template<class T> struct mp_identity
{
using type = T;
};
// mp_inherit
template<class... T> struct mp_inherit: T... {};
// mp_if
template<bool C, class T, class E> struct mp_if_c_impl;
template<class T, class E> struct mp_if_c_impl<true, T, E>
{
using type = T;
};
template<class T, class E> struct mp_if_c_impl<false, T, E>
{
using type = E;
};
template<bool C, class T, class E> using mp_if_c = typename mp_if_c_impl<C, T, E>::type;
template<class C, class T, class E> using mp_if = typename mp_if_c_impl<static_cast<bool>( C::value ), T, E>::type;
// mp_eval_if
template<bool C, class T, template<class...> class F, class... U> struct mp_eval_if_c_impl;
template<class T, template<class...> class F, class... U> struct mp_eval_if_c_impl<true, T, F, U...>
{
using type = T;
};
template<class T, template<class...> class F, class... U> struct mp_eval_if_c_impl<false, T, F, U...>
{
using type = F<U...>;
};
template<bool C, class T, template<class...> class F, class... U> using mp_eval_if_c = typename mp_eval_if_c_impl<C, T, F, U...>::type;
template<class C, class T, template<class...> class F, class... U> using mp_eval_if = typename mp_eval_if_c_impl<static_cast<bool>( C::value ), T, F, U...>::type;
} // namespace boost
#endif // #ifndef BOOST_MP11_UTILITY_HPP_INCLUDED

14
meta/libraries.json Normal file
View File

@@ -0,0 +1,14 @@
{
"key": "mp11",
"name": "Mp11",
"authors": [
"Peter Dimov"
],
"maintainers": [
"Peter Dimov <pdimov -at- pdimov.com>"
],
"description": "Simple C++11 metaprogramming library.",
"category": [
"Metaprogramming"
]
}

41
test/Jamfile.v2 Normal file
View File

@@ -0,0 +1,41 @@
# Boost.Mp11 Library Test Jamfile
#
# Copyright 2015 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
import testing ;
import ../../config/checks/config : requires ;
REQ = ; #[ requires cxx11_variadic_templates cxx11_template_aliases cxx11_hdr_type_traits cxx11_hdr_tuple ] ;
# list
run mp_size.cpp : : : $(REQ) ;
run mp_empty.cpp : : : $(REQ) ;
run mp_front.cpp : : : $(REQ) ;
run mp_pop_front.cpp : : : $(REQ) ;
run mp_second.cpp : : : $(REQ) ;
run mp_third.cpp : : : $(REQ) ;
run mp_push_front.cpp : : : $(REQ) ;
run mp_push_back.cpp : : : $(REQ) ;
run mp_rename.cpp : : : $(REQ) ;
run mp_append.cpp : : : $(REQ) ;
run mp_assign.cpp : : : $(REQ) ;
run mp_clear.cpp : : : $(REQ) ;
#run mp_transform.cpp : : : $(REQ) ;
run mp_fill.cpp : : : $(REQ) ;
#run mp_count.cpp : : : $(REQ) ;
#run mp_count_if.cpp : : : $(REQ) ;
#run mp_contains.cpp : : : $(REQ) ;
run mp_repeat.cpp : : : $(REQ) ;
# integral
run integral.cpp : : : $(REQ) ;
# utility
run mp_identity.cpp : : : $(REQ) ;
run mp_inherit.cpp : : : $(REQ) ;
run mp_if.cpp : : : $(REQ) ;
run mp_eval_if.cpp : : : $(REQ) ;

55
test/integral.cpp Normal file
View File

@@ -0,0 +1,55 @@
// Copyright 2015 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/core/lightweight_test_trait.hpp>
#include <boost/mp11/integral.hpp>
#include <type_traits>
#include <cstddef>
int main()
{
using boost::mp_bool;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_bool<false>, std::integral_constant<bool, false>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_bool<true>, std::integral_constant<bool, true>>));
using boost::mp_true;
using boost::mp_false;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_false, std::integral_constant<bool, false>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_true, std::integral_constant<bool, true>>));
using boost::mp_int;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_int<0>, std::integral_constant<int, 0>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_int<814>, std::integral_constant<int, 814>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_int<-144>, std::integral_constant<int, -144>>));
using boost::mp_size_t;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_size_t<0>, std::integral_constant<std::size_t, 0>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_size_t<1972>, std::integral_constant<std::size_t, 1972>>));
using boost::mp_to_bool;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_to_bool<mp_false>, mp_false>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_to_bool<mp_true>, mp_true>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_to_bool<mp_int<0>>, mp_false>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_to_bool<mp_int<1>>, mp_true>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_to_bool<mp_int<107>>, mp_true>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_to_bool<mp_int<-1>>, mp_true>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_to_bool<mp_int<-91>>, mp_true>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_to_bool<mp_size_t<0>>, mp_false>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_to_bool<mp_size_t<1>>, mp_true>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_to_bool<mp_size_t<442>>, mp_true>));
return boost::report_errors();
}

76
test/mp_append.cpp Normal file
View File

@@ -0,0 +1,76 @@
// Copyright 2015 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/core/lightweight_test_trait.hpp>
#include <boost/mp11/list.hpp>
#include <type_traits>
#include <tuple>
#include <utility>
struct X1 {};
struct X2 {};
struct X3 {};
struct X4 {};
struct X5 {};
struct X6 {};
int main()
{
using boost::mp_list;
using boost::mp_append;
using L1 = mp_list<char[1], char[1]>;
using L2 = mp_list<char[2], char[2]>;
using L3 = mp_list<char[3], char[3]>;
using L4 = mp_list<char[4], char[4]>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_append<>, mp_list<>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_append<L1>, mp_list<char[1], char[1]>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_append<L1, L2>, mp_list<char[1], char[1], char[2], char[2]>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_append<L1, L2, L3>, mp_list<char[1], char[1], char[2], char[2], char[3], char[3]>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_append<L1, L2, L3, L4>, mp_list<char[1], char[1], char[2], char[2], char[3], char[3], char[4], char[4]>>));
//
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_append<std::tuple<>>, std::tuple<>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_append<std::tuple<>, std::tuple<X1>>, std::tuple<X1>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_append<std::tuple<>, std::tuple<X1>, std::tuple<X2>>, std::tuple<X1, X2>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_append<std::tuple<>, std::tuple<X1>, std::tuple<X2>, std::tuple<X3>>, std::tuple<X1, X2, X3>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_append<std::tuple<>, std::tuple<X1>, std::tuple<X2>, std::tuple<X3>, std::tuple<X4>>, std::tuple<X1, X2, X3, X4>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_append<std::tuple<>, std::tuple<X1>, std::tuple<X2>, std::tuple<X3>, std::tuple<X4>, std::tuple<X5>>, std::tuple<X1, X2, X3, X4, X5>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_append<std::tuple<>, std::tuple<X1>, std::tuple<X2>, std::tuple<X3>, std::tuple<X4>, std::tuple<X5>, std::tuple<X6>>, std::tuple<X1, X2, X3, X4, X5, X6>>));
//
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_append<std::tuple<>, mp_list<>>, std::tuple<>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_append<std::tuple<>, mp_list<X1>>, std::tuple<X1>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_append<std::tuple<>, mp_list<X1>, std::tuple<X2>>, std::tuple<X1, X2>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_append<std::tuple<>, mp_list<X1>, std::tuple<X2>, mp_list<X3>>, std::tuple<X1, X2, X3>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_append<std::tuple<>, mp_list<X1>, std::tuple<X2>, mp_list<X3>, std::tuple<X4>>, std::tuple<X1, X2, X3, X4>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_append<std::tuple<>, mp_list<X1>, std::tuple<X2>, mp_list<X3>, std::tuple<X4>, mp_list<X5>>, std::tuple<X1, X2, X3, X4, X5>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_append<std::tuple<>, mp_list<X1>, std::tuple<X2>, mp_list<X3>, std::tuple<X4>, mp_list<X5>, std::tuple<X6>>, std::tuple<X1, X2, X3, X4, X5, X6>>));
//
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_append<std::tuple<>, std::pair<X1, X2>>, std::tuple<X1, X2>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_append<std::tuple<>, std::pair<X1, X2>, std::pair<X3, X4>>, std::tuple<X1, X2, X3, X4>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_append<std::tuple<>, std::pair<X1, X2>, std::pair<X3, X4>, std::pair<X5, X6>>, std::tuple<X1, X2, X3, X4, X5, X6>>));
//
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_append<std::pair<X1, X2>>, std::pair<X1, X2>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_append<std::pair<X1, X2>, mp_list<>>, std::pair<X1, X2>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_append<std::pair<X1, X2>, mp_list<>, mp_list<>>, std::pair<X1, X2>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_append<std::pair<X1, X2>, mp_list<>, mp_list<>, mp_list<>>, std::pair<X1, X2>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_append<std::pair<X1, X2>, mp_list<>, mp_list<>, mp_list<>, mp_list<>>, std::pair<X1, X2>>));
//
return boost::report_errors();
}

64
test/mp_assign.cpp Normal file
View File

@@ -0,0 +1,64 @@
// Copyright 2015 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/core/lightweight_test_trait.hpp>
#include <boost/mp11/list.hpp>
#include <type_traits>
#include <tuple>
#include <utility>
struct X1 {};
struct X2 {};
struct X3 {};
int main()
{
using boost::mp_list;
using boost::mp_assign;
using L1 = mp_list<int, void(), float[]>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_assign<L1, mp_list<>>, mp_list<>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_assign<L1, mp_list<X1>>, mp_list<X1>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_assign<L1, mp_list<X1, X2>>, mp_list<X1, X2>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_assign<L1, mp_list<X1, X2, X3>>, mp_list<X1, X2, X3>>));
//
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_assign<L1, std::tuple<>>, mp_list<>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_assign<L1, std::tuple<X1>>, mp_list<X1>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_assign<L1, std::tuple<X1, X2>>, mp_list<X1, X2>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_assign<L1, std::tuple<X1, X2, X3>>, mp_list<X1, X2, X3>>));
//
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_assign<L1, std::pair<X1, X2>>, mp_list<X1, X2>>));
//
using L2 = std::tuple<int, char, float>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_assign<L2, mp_list<>>, std::tuple<>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_assign<L2, mp_list<X1>>, std::tuple<X1>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_assign<L2, mp_list<X1, X2>>, std::tuple<X1, X2>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_assign<L2, mp_list<X1, X2, X3>>, std::tuple<X1, X2, X3>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_assign<L2, std::pair<X1, X2>>, std::tuple<X1, X2>>));
//
using L3 = std::pair<int, char>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_assign<L3, mp_list<X1, X2>>, std::pair<X1, X2>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_assign<L3, std::pair<X1, X2>>, std::pair<X1, X2>>));
//
return boost::report_errors();
}

32
test/mp_clear.cpp Normal file
View File

@@ -0,0 +1,32 @@
// Copyright 2015 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/core/lightweight_test_trait.hpp>
#include <boost/mp11/list.hpp>
#include <type_traits>
#include <tuple>
#include <utility>
int main()
{
using boost::mp_list;
using boost::mp_clear;
using L1 = mp_list<int, void(), float[]>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_clear<L1>, mp_list<>>));
//
using L2 = std::tuple<int, char, float>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_clear<L2>, std::tuple<>>));
//
return boost::report_errors();
}

49
test/mp_empty.cpp Normal file
View File

@@ -0,0 +1,49 @@
// Copyright 2015 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/core/lightweight_test_trait.hpp>
#include <boost/mp11/list.hpp>
#include <boost/mp11/integral.hpp>
#include <type_traits>
#include <tuple>
#include <utility>
int main()
{
using boost::mp_list;
using boost::mp_empty;
using boost::mp_true;
using boost::mp_false;
using L1 = mp_list<>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_empty<L1>, mp_true>));
using L2 = mp_list<void>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_empty<L2>, mp_false>));
using L3 = mp_list<int[], void, float>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_empty<L3>, mp_false>));
using L4 = std::tuple<>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_empty<L4>, mp_true>));
using L5 = std::tuple<int>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_empty<L5>, mp_false>));
using L6 = std::tuple<int, int>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_empty<L6>, mp_false>));
using L7 = std::pair<char, double>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_empty<L7>, mp_false>));
using L8 = std::add_const<void()>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_empty<L8>, mp_false>));
return boost::report_errors();
}

39
test/mp_eval_if.cpp Normal file
View File

@@ -0,0 +1,39 @@
// Copyright 2015 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/core/lightweight_test_trait.hpp>
#include <boost/mp11/utility.hpp>
#include <boost/mp11/integral.hpp>
#include <type_traits>
int main()
{
using boost::mp_eval_if_c;
using boost::mp_identity;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_eval_if_c<true, char[], mp_identity, void, void, void>, char[]>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_eval_if_c<false, char[], mp_identity, void()>, mp_identity<void()>>));
using boost::mp_eval_if;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_eval_if<std::true_type, char[], mp_identity, void, void, void>, char[]>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_eval_if<std::false_type, char[], mp_identity, void()>, mp_identity<void()>>));
using boost::mp_int;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_eval_if<mp_int<-7>, char[], mp_identity, void, void, void>, char[]>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_eval_if<mp_int<0>, char[], mp_identity, void()>, mp_identity<void()>>));
using boost::mp_size_t;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_eval_if<mp_size_t<14>, char[], mp_identity, void, void, void>, char[]>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_eval_if<mp_size_t<0>, char[], mp_identity, void()>, mp_identity<void()>>));
return boost::report_errors();
}

39
test/mp_fill.cpp Normal file
View File

@@ -0,0 +1,39 @@
// Copyright 2015 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/core/lightweight_test_trait.hpp>
#include <boost/mp11/list.hpp>
#include <type_traits>
#include <tuple>
#include <utility>
struct X1 {};
int main()
{
using boost::mp_list;
using boost::mp_fill;
using L1 = mp_list<int, void(), float[]>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_fill<L1, X1>, mp_list<X1, X1, X1>>));
//
using L2 = std::tuple<int, char, float>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_fill<L2, X1>, std::tuple<X1, X1, X1>>));
//
using L3 = std::pair<char, double>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_fill<L3, X1>, std::pair<X1, X1>>));
//
return boost::report_errors();
}

43
test/mp_front.cpp Normal file
View File

@@ -0,0 +1,43 @@
// Copyright 2015 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/core/lightweight_test_trait.hpp>
#include <boost/mp11/list.hpp>
#include <type_traits>
#include <tuple>
#include <utility>
int main()
{
using boost::mp_list;
using boost::mp_front;
using boost::mp_first;
using L1 = mp_list<void>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_front<L1>, void>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_first<L1>, void>));
using L2 = mp_list<int[], void, float>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_front<L2>, int[]>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_first<L2>, int[]>));
using L3 = std::tuple<int>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_front<L3>, int>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_first<L3>, int>));
using L4 = std::pair<char, double>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_front<L4>, char>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_first<L4>, char>));
using L5 = std::add_const<void()>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_front<L5>, void()>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_first<L5>, void()>));
return boost::report_errors();
}

26
test/mp_identity.cpp Normal file
View File

@@ -0,0 +1,26 @@
// Copyright 2015 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/core/lightweight_test_trait.hpp>
#include <boost/mp11/utility.hpp>
#include <type_traits>
struct X {};
int main()
{
using boost::mp_identity;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_identity<void const volatile>::type, void const volatile>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_identity<void()>::type, void()>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_identity<int const[]>::type, int const[]>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_identity<X>::type, X>));
return boost::report_errors();
}

38
test/mp_if.cpp Normal file
View File

@@ -0,0 +1,38 @@
// Copyright 2015 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/core/lightweight_test_trait.hpp>
#include <boost/mp11/utility.hpp>
#include <boost/mp11/integral.hpp>
#include <type_traits>
int main()
{
using boost::mp_if_c;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_if_c<true, char[], void()>, char[]>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_if_c<false, char[], void()>, void()>));
using boost::mp_if;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_if<std::true_type, char[], void()>, char[]>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_if<std::false_type, char[], void()>, void()>));
using boost::mp_int;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_if<mp_int<-7>, char[], void()>, char[]>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_if<mp_int<0>, char[], void()>, void()>));
using boost::mp_size_t;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_if<mp_size_t<14>, char[], void()>, char[]>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_if<mp_size_t<0>, char[], void()>, void()>));
return boost::report_errors();
}

27
test/mp_inherit.cpp Normal file
View File

@@ -0,0 +1,27 @@
// Copyright 2015 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/core/lightweight_test_trait.hpp>
#include <boost/mp11/utility.hpp>
#include <type_traits>
struct X1 {};
struct X2 {};
struct X3 {};
int main()
{
using boost::mp_inherit;
BOOST_TEST_TRAIT_TRUE((std::is_base_of<X1, mp_inherit<X1, X2, X3>>));
BOOST_TEST_TRAIT_TRUE((std::is_base_of<X2, mp_inherit<X1, X2, X3>>));
BOOST_TEST_TRAIT_TRUE((std::is_base_of<X3, mp_inherit<X1, X2, X3>>));
return boost::report_errors();
}

39
test/mp_pop_front.cpp Normal file
View File

@@ -0,0 +1,39 @@
// Copyright 2015 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/core/lightweight_test_trait.hpp>
#include <boost/mp11/list.hpp>
#include <type_traits>
#include <tuple>
#include <utility>
int main()
{
using boost::mp_list;
using boost::mp_pop_front;
using boost::mp_rest;
using L1 = mp_list<void>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_pop_front<L1>, mp_list<>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rest<L1>, mp_list<>>));
using L2 = mp_list<int[], void(), float>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_pop_front<L2>, mp_list<void(), float>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rest<L2>, mp_list<void(), float>>));
using L3 = std::tuple<int>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_pop_front<L3>, std::tuple<>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rest<L3>, std::tuple<>>));
using L4 = std::tuple<char, double>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_pop_front<L4>, std::tuple<double>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rest<L4>, std::tuple<double>>));
return boost::report_errors();
}

52
test/mp_push_back.cpp Normal file
View File

@@ -0,0 +1,52 @@
// Copyright 2015 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/core/lightweight_test_trait.hpp>
#include <boost/mp11/list.hpp>
#include <type_traits>
#include <tuple>
#include <utility>
int main()
{
using boost::mp_list;
using boost::mp_push_back;
using L1 = mp_list<>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_push_back<L1>, mp_list<>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_push_back<L1, char[1]>, mp_list<char[1]>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_push_back<L1, char[1], char[2]>, mp_list<char[1], char[2]>>));
using L2 = mp_list<void>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_push_back<L2>, mp_list<void>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_push_back<L2, char[1]>, mp_list<void, char[1]>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_push_back<L2, char[1], char[2]>, mp_list<void, char[1], char[2]>>));
using L3 = mp_list<int[], void, float>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_push_back<L3>, mp_list<int[], void, float>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_push_back<L3, char[1]>, mp_list<int[], void, float, char[1]>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_push_back<L3, char[1], char[2]>, mp_list<int[], void, float, char[1], char[2]>>));
using L4 = std::tuple<>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_push_back<L4>, std::tuple<>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_push_back<L4, char>, std::tuple<char>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_push_back<L4, char, wchar_t>, std::tuple<char, wchar_t>>));
using L5 = std::tuple<int>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_push_back<L5>, std::tuple<int>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_push_back<L5, char>, std::tuple<int, char>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_push_back<L5, char, wchar_t>, std::tuple<int, char, wchar_t>>));
using L6 = std::tuple<int, int>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_push_back<L6>, std::tuple<int, int>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_push_back<L6, char>, std::tuple<int, int, char>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_push_back<L6, char, wchar_t>, std::tuple<int, int, char, wchar_t>>));
return boost::report_errors();
}

52
test/mp_push_front.cpp Normal file
View File

@@ -0,0 +1,52 @@
// Copyright 2015 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/core/lightweight_test_trait.hpp>
#include <boost/mp11/list.hpp>
#include <type_traits>
#include <tuple>
#include <utility>
int main()
{
using boost::mp_list;
using boost::mp_push_front;
using L1 = mp_list<>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_push_front<L1>, mp_list<>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_push_front<L1, char[1]>, mp_list<char[1]>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_push_front<L1, char[1], char[2]>, mp_list<char[1], char[2]>>));
using L2 = mp_list<void>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_push_front<L2>, mp_list<void>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_push_front<L2, char[1]>, mp_list<char[1], void>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_push_front<L2, char[1], char[2]>, mp_list<char[1], char[2], void>>));
using L3 = mp_list<int[], void, float>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_push_front<L3>, mp_list<int[], void, float>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_push_front<L3, char[1]>, mp_list<char[1], int[], void, float>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_push_front<L3, char[1], char[2]>, mp_list<char[1], char[2], int[], void, float>>));
using L4 = std::tuple<>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_push_front<L4>, std::tuple<>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_push_front<L4, char>, std::tuple<char>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_push_front<L4, char, wchar_t>, std::tuple<char, wchar_t>>));
using L5 = std::tuple<int>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_push_front<L5>, std::tuple<int>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_push_front<L5, char>, std::tuple<char, int>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_push_front<L5, char, wchar_t>, std::tuple<char, wchar_t, int>>));
using L6 = std::tuple<int, int>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_push_front<L6>, std::tuple<int, int>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_push_front<L6, char>, std::tuple<char, int, int>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_push_front<L6, char, wchar_t>, std::tuple<char, wchar_t, int, int>>));
return boost::report_errors();
}

88
test/mp_rename.cpp Normal file
View File

@@ -0,0 +1,88 @@
// Copyright 2015 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/core/lightweight_test_trait.hpp>
#include <boost/mp11/list.hpp>
#include <type_traits>
#include <tuple>
#include <utility>
template<class... T> struct X {};
template<class... T> using Y = X<T...>;
int main()
{
using boost::mp_list;
using boost::mp_rename;
using L1 = mp_list<>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rename<L1, mp_list>, mp_list<>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rename<L1, std::tuple>, std::tuple<>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rename<L1, X>, X<>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rename<L1, Y>, Y<>>));
using L2 = mp_list<char>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rename<L2, mp_list>, mp_list<char>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rename<L2, std::tuple>, std::tuple<char>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rename<L2, X>, X<char>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rename<L2, Y>, Y<char>>));
using L3 = mp_list<char, double>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rename<L3, mp_list>, mp_list<char, double>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rename<L3, std::tuple>, std::tuple<char, double>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rename<L3, X>, X<char, double>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rename<L3, Y>, Y<char, double>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rename<L3, std::pair>, std::pair<char, double>>));
using L4 = mp_list<int, char, float>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rename<L4, mp_list>, mp_list<int, char, float>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rename<L4, std::tuple>, std::tuple<int, char, float>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rename<L4, X>, X<int, char, float>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rename<L4, Y>, Y<int, char, float>>));
//
using L5 = std::tuple<>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rename<L5, mp_list>, mp_list<>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rename<L5, std::tuple>, std::tuple<>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rename<L5, X>, X<>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rename<L5, Y>, Y<>>));
using L6 = std::tuple<char>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rename<L6, mp_list>, mp_list<char>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rename<L6, std::tuple>, std::tuple<char>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rename<L6, X>, X<char>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rename<L6, Y>, Y<char>>));
using L7 = std::tuple<char, double>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rename<L7, mp_list>, mp_list<char, double>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rename<L7, std::tuple>, std::tuple<char, double>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rename<L7, X>, X<char, double>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rename<L7, Y>, Y<char, double>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rename<L7, std::pair>, std::pair<char, double>>));
using L8 = std::tuple<int, char, float>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rename<L8, mp_list>, mp_list<int, char, float>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rename<L8, std::tuple>, std::tuple<int, char, float>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rename<L8, X>, X<int, char, float>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rename<L8, Y>, Y<int, char, float>>));
//
using L9 = std::pair<char, double>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rename<L9, mp_list>, mp_list<char, double>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rename<L9, std::tuple>, std::tuple<char, double>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rename<L9, X>, X<char, double>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rename<L9, Y>, Y<char, double>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rename<L9, std::pair>, std::pair<char, double>>));
//
return boost::report_errors();
}

131
test/mp_repeat.cpp Normal file
View File

@@ -0,0 +1,131 @@
// Copyright 2015 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/core/lightweight_test_trait.hpp>
#include <boost/mp11/list.hpp>
#include <boost/mp11/integral.hpp>
#include <type_traits>
#include <tuple>
#include <utility>
struct X1 {};
struct X2 {};
int main()
{
using boost::mp_list;
using boost::mp_repeat;
using boost::mp_repeat_c;
using boost::mp_true;
using boost::mp_false;
using boost::mp_int;
using boost::mp_size_t;
using L1 = mp_list<>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_repeat_c<L1, 0>, mp_list<>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_repeat_c<L1, 1>, mp_list<>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_repeat_c<L1, 2>, mp_list<>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_repeat_c<L1, 3>, mp_list<>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_repeat_c<L1, 31>, mp_list<>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_repeat<L1, mp_false>, mp_list<>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_repeat<L1, mp_true>, mp_list<>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_repeat<L1, mp_int<2>>, mp_list<>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_repeat<L1, mp_int<3>>, mp_list<>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_repeat<L1, mp_size_t<31>>, mp_list<>>));
using L2 = mp_list<X1>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_repeat_c<L2, 0>, mp_list<>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_repeat_c<L2, 1>, mp_list<X1>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_repeat_c<L2, 2>, mp_list<X1, X1>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_repeat_c<L2, 3>, mp_list<X1, X1, X1>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_repeat_c<L2, 4>, mp_list<X1, X1, X1, X1>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_repeat_c<L2, 5>, mp_list<X1, X1, X1, X1, X1>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_repeat_c<L2, 6>, mp_list<X1, X1, X1, X1, X1, X1>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_repeat<L2, mp_false>, mp_list<>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_repeat<L2, mp_true>, mp_list<X1>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_repeat<L2, mp_int<2>>, mp_list<X1, X1>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_repeat<L2, mp_int<3>>, mp_list<X1, X1, X1>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_repeat<L2, mp_int<4>>, mp_list<X1, X1, X1, X1>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_repeat<L2, mp_size_t<5>>, mp_list<X1, X1, X1, X1, X1>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_repeat<L2, mp_size_t<6>>, mp_list<X1, X1, X1, X1, X1, X1>>));
using L3 = mp_list<X1, X2>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_repeat_c<L3, 0>, mp_list<>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_repeat_c<L3, 1>, mp_list<X1, X2>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_repeat_c<L3, 2>, mp_list<X1, X2, X1, X2>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_repeat_c<L3, 3>, mp_list<X1, X2, X1, X2, X1, X2>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_repeat<L3, mp_false>, mp_list<>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_repeat<L3, mp_true>, mp_list<X1, X2>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_repeat<L3, mp_int<2>>, mp_list<X1, X2, X1, X2>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_repeat<L3, mp_size_t<3>>, mp_list<X1, X2, X1, X2, X1, X2>>));
//
using L4 = std::tuple<>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_repeat_c<L4, 0>, std::tuple<>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_repeat_c<L4, 1>, std::tuple<>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_repeat_c<L4, 2>, std::tuple<>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_repeat_c<L4, 3>, std::tuple<>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_repeat_c<L4, 31>, std::tuple<>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_repeat<L4, mp_false>, std::tuple<>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_repeat<L4, mp_true>, std::tuple<>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_repeat<L4, mp_int<2>>, std::tuple<>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_repeat<L4, mp_int<3>>, std::tuple<>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_repeat<L4, mp_size_t<31>>, std::tuple<>>));
using L5 = std::tuple<X1>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_repeat_c<L5, 0>, std::tuple<>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_repeat_c<L5, 1>, std::tuple<X1>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_repeat_c<L5, 2>, std::tuple<X1, X1>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_repeat_c<L5, 3>, std::tuple<X1, X1, X1>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_repeat_c<L5, 4>, std::tuple<X1, X1, X1, X1>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_repeat_c<L5, 5>, std::tuple<X1, X1, X1, X1, X1>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_repeat_c<L5, 6>, std::tuple<X1, X1, X1, X1, X1, X1>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_repeat<L5, mp_false>, std::tuple<>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_repeat<L5, mp_true>, std::tuple<X1>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_repeat<L5, mp_int<2>>, std::tuple<X1, X1>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_repeat<L5, mp_int<3>>, std::tuple<X1, X1, X1>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_repeat<L5, mp_int<4>>, std::tuple<X1, X1, X1, X1>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_repeat<L5, mp_size_t<5>>, std::tuple<X1, X1, X1, X1, X1>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_repeat<L5, mp_size_t<6>>, std::tuple<X1, X1, X1, X1, X1, X1>>));
using L6 = std::tuple<X1, X2>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_repeat_c<L6, 0>, std::tuple<>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_repeat_c<L6, 1>, std::tuple<X1, X2>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_repeat_c<L6, 2>, std::tuple<X1, X2, X1, X2>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_repeat_c<L6, 3>, std::tuple<X1, X2, X1, X2, X1, X2>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_repeat<L6, mp_false>, std::tuple<>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_repeat<L6, mp_true>, std::tuple<X1, X2>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_repeat<L6, mp_int<2>>, std::tuple<X1, X2, X1, X2>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_repeat<L6, mp_size_t<3>>, std::tuple<X1, X2, X1, X2, X1, X2>>));
//
using L7 = std::pair<X1, X2>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_repeat_c<L7, 1>, std::pair<X1, X2>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_repeat<L7, mp_true>, std::pair<X1, X2>>));
//
return boost::report_errors();
}

34
test/mp_second.cpp Normal file
View File

@@ -0,0 +1,34 @@
// Copyright 2015 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/core/lightweight_test_trait.hpp>
#include <boost/mp11/list.hpp>
#include <type_traits>
#include <tuple>
#include <utility>
int main()
{
using boost::mp_list;
using boost::mp_second;
using L1 = mp_list<void, char[]>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_second<L1>, char[]>));
using L2 = mp_list<int[], void, float>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_second<L2>, void>));
using L3 = std::tuple<int, float>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_second<L3>, float>));
using L4 = std::pair<char, double>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_second<L4>, double>));
return boost::report_errors();
}

48
test/mp_size.cpp Normal file
View File

@@ -0,0 +1,48 @@
// Copyright 2015 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/core/lightweight_test_trait.hpp>
#include <boost/mp11/list.hpp>
#include <boost/mp11/integral.hpp>
#include <type_traits>
#include <tuple>
#include <utility>
int main()
{
using boost::mp_list;
using boost::mp_size;
using boost::mp_size_t;
using L1 = mp_list<>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_size<L1>, mp_size_t<0>>));
using L2 = mp_list<void>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_size<L2>, mp_size_t<1>>));
using L3 = mp_list<int[], void, float>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_size<L3>, mp_size_t<3>>));
using L4 = std::tuple<>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_size<L4>, mp_size_t<0>>));
using L5 = std::tuple<int>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_size<L5>, mp_size_t<1>>));
using L6 = std::tuple<int, int>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_size<L6>, mp_size_t<2>>));
using L7 = std::pair<char, double>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_size<L7>, mp_size_t<2>>));
using L8 = std::add_const<void()>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_size<L8>, mp_size_t<1>>));
return boost::report_errors();
}

28
test/mp_third.cpp Normal file
View File

@@ -0,0 +1,28 @@
// Copyright 2015 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/core/lightweight_test_trait.hpp>
#include <boost/mp11/list.hpp>
#include <type_traits>
#include <tuple>
#include <utility>
int main()
{
using boost::mp_list;
using boost::mp_third;
using L1 = mp_list<int[], void, float[]>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_third<L1>, float[]>));
using L2 = std::tuple<int, float, char>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_third<L2>, char>));
return boost::report_errors();
}