Added tests for support/pair

This commit is contained in:
Kohei Takahashi
2018-03-23 02:25:38 +09:00
parent e3b053f969
commit 44ef9e56e6
4 changed files with 104 additions and 4 deletions

View File

@ -255,6 +255,7 @@ project
[ run sequence/swap.cpp ] [ run sequence/swap.cpp ]
[ compile support/is_sequence.cpp ] [ compile support/is_sequence.cpp ]
[ compile support/pair_conversion.cpp ]
[ compile support/pair_deque.cpp ] [ compile support/pair_deque.cpp ]
[ compile support/pair_list.cpp ] [ compile support/pair_list.cpp ]
[ compile support/pair_map.cpp ] [ compile support/pair_map.cpp ]
@ -266,6 +267,8 @@ project
[ compile support/and.cpp [ compile support/and.cpp
: [ requires cxx11_variadic_templates ] ] : [ requires cxx11_variadic_templates ] ]
[ compile support/tag_of.cpp ] [ compile support/tag_of.cpp ]
[ compile support/pair_trivially_copyable.cpp
: [ requires cxx11_hdr_type_traits ] ]
# [ compile-fail xxx.cpp ] # [ compile-fail xxx.cpp ]

View File

@ -0,0 +1,42 @@
/*=============================================================================
Copyright (c) 2018 Kohei Takahashi
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 <utility>
#include <boost/config.hpp>
#include <boost/fusion/support/pair.hpp>
using namespace boost::fusion;
struct eat_int
{
eat_int(int);
};
struct eat_pair
{
template <typename K, typename V>
eat_pair(pair<K, V>);
};
int main()
{
pair<void, int> p;
pair<void, eat_int> ci(p);
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
pair<void, eat_int> mi(std::move(p));
#endif
// eat_pair can't be converted from int, but can be pair.
// So pair(eat_pair) should be called rather than pair(pair<void, eat_pair>).
pair<void, eat_pair> cp(p);
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
pair<void, eat_pair> mp(std::move(p));
#endif
}

View File

@ -1,5 +1,5 @@
/*============================================================================= /*=============================================================================
Copyright (c) 2015 Kohei Takahashi Copyright (c) 2015,2018 Kohei Takahashi
Distributed under the Boost Software License, Version 1.0. (See accompanying 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) file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@ -10,15 +10,20 @@
using namespace boost::fusion; using namespace boost::fusion;
template <typename C> template <typename C>
void copy() void copy(C value)
{ {
pair<int, C> src; pair<int, C> src(value);
pair<int, C> dest = src; pair<int, C> dest = src;
boost::ignore_unused(dest); boost::ignore_unused(dest);
} }
int main() int main()
{ {
copy<pair<void, float> >(); copy<pair<void, float> >(42.195f);
copy<pair<int, float> >(42.195f);
float f;
pair<void, float&> r(f);
copy<pair<void, float&> >(r);
} }

View File

@ -0,0 +1,50 @@
/*=============================================================================
Copyright (c) 2018 Kohei Takahashi
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 <boost/fusion/support/pair.hpp>
#include <boost/mpl/assert.hpp>
using namespace boost::fusion;
struct non_trivially_copyable
{
non_trivially_copyable(const non_trivially_copyable&);
non_trivially_copyable operator=(const non_trivially_copyable&);
};
struct pod { };
BOOST_MPL_ASSERT_NOT((std::is_trivially_copyable<void>));
BOOST_MPL_ASSERT((std::is_trivially_copyable<int>));
BOOST_MPL_ASSERT_NOT((std::is_trivially_copyable<non_trivially_copyable>));
BOOST_MPL_ASSERT((std::is_trivially_copyable<pod>));
BOOST_MPL_ASSERT_NOT((std::is_trivially_copyable<int&>));
BOOST_MPL_ASSERT((std::is_trivially_copyable<void*>));
BOOST_MPL_ASSERT((std::is_trivially_copyable<pair<void, int> >));
BOOST_MPL_ASSERT((std::is_trivially_copyable<pair<int, int> >));
BOOST_MPL_ASSERT((std::is_trivially_copyable<pair<non_trivially_copyable, int> >));
BOOST_MPL_ASSERT_NOT((std::is_trivially_copyable<pair<int, non_trivially_copyable> >));
BOOST_MPL_ASSERT((std::is_trivially_copyable<pair<pod, int> >));
BOOST_MPL_ASSERT((std::is_trivially_copyable<pair<int, pod> >));
BOOST_MPL_ASSERT((std::is_trivially_copyable<pair<void, int&> >));
BOOST_MPL_ASSERT((std::is_trivially_copyable<pair<int, int&> >));
BOOST_MPL_ASSERT((std::is_trivially_copyable<pair<non_trivially_copyable, int&> >));
BOOST_MPL_ASSERT((std::is_trivially_copyable<pair<int, non_trivially_copyable&> >));
BOOST_MPL_ASSERT((std::is_trivially_copyable<pair<int, pod&> >));
BOOST_MPL_ASSERT((std::is_trivially_copyable<pair<int, pod&> >));
BOOST_MPL_ASSERT((std::is_trivially_copyable<pair<void, int*> >));
BOOST_MPL_ASSERT((std::is_trivially_copyable<pair<int, int*> >));
BOOST_MPL_ASSERT((std::is_trivially_copyable<pair<non_trivially_copyable, int*> >));
BOOST_MPL_ASSERT((std::is_trivially_copyable<pair<int, non_trivially_copyable*> >));
BOOST_MPL_ASSERT((std::is_trivially_copyable<pair<int, pod*> >));
BOOST_MPL_ASSERT((std::is_trivially_copyable<pair<int, pod*> >));