mirror of
https://github.com/boostorg/fusion.git
synced 2025-07-19 07:12:12 +02:00
Updated c-style array test for associative container
This commit is contained in:
@ -6,9 +6,12 @@
|
|||||||
==============================================================================*/
|
==============================================================================*/
|
||||||
|
|
||||||
#include <boost/fusion/sequence/intrinsic/at.hpp>
|
#include <boost/fusion/sequence/intrinsic/at.hpp>
|
||||||
|
#include <boost/fusion/sequence/intrinsic/at_key.hpp>
|
||||||
#include <boost/fusion/container/vector.hpp>
|
#include <boost/fusion/container/vector.hpp>
|
||||||
#include <boost/fusion/container/list.hpp>
|
#include <boost/fusion/container/list.hpp>
|
||||||
#include <boost/fusion/container/deque.hpp>
|
#include <boost/fusion/container/deque.hpp>
|
||||||
|
#include <boost/fusion/container/map.hpp>
|
||||||
|
#include <boost/fusion/container/set.hpp>
|
||||||
#include <boost/fusion/tuple/tuple.hpp>
|
#include <boost/fusion/tuple/tuple.hpp>
|
||||||
#include <boost/core/lightweight_test.hpp>
|
#include <boost/core/lightweight_test.hpp>
|
||||||
|
|
||||||
@ -39,6 +42,36 @@ void test_at()
|
|||||||
BOOST_TEST(boost::fusion::at_c<0>(seq)[2] == 6);
|
BOOST_TEST(boost::fusion::at_c<0>(seq)[2] == 6);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T> inline T& value(T& v) { return v; }
|
||||||
|
template <typename K, typename T> inline T& value(boost::fusion::pair<K, T>& v) { return v.second; }
|
||||||
|
|
||||||
|
template <typename Sequence>
|
||||||
|
void test_at_key()
|
||||||
|
{
|
||||||
|
Sequence seq;
|
||||||
|
|
||||||
|
// zero initialized
|
||||||
|
BOOST_TEST(boost::fusion::at_key<int[3]>(seq)[0] == 0);
|
||||||
|
BOOST_TEST(boost::fusion::at_key<int[3]>(seq)[1] == 0);
|
||||||
|
BOOST_TEST(boost::fusion::at_key<int[3]>(seq)[2] == 0);
|
||||||
|
|
||||||
|
int (&arr)[3] = value(boost::fusion::deref(boost::fusion::begin(seq)));
|
||||||
|
|
||||||
|
arr[0] = 2;
|
||||||
|
arr[1] = 4;
|
||||||
|
arr[2] = 6;
|
||||||
|
|
||||||
|
BOOST_TEST(boost::fusion::at_key<int[3]>(seq)[0] == 2);
|
||||||
|
BOOST_TEST(boost::fusion::at_key<int[3]>(seq)[1] == 4);
|
||||||
|
BOOST_TEST(boost::fusion::at_key<int[3]>(seq)[2] == 6);
|
||||||
|
|
||||||
|
boost::fusion::at_key<int[3]>(seq)[1] = 42;
|
||||||
|
|
||||||
|
BOOST_TEST(boost::fusion::at_key<int[3]>(seq)[0] == 2);
|
||||||
|
BOOST_TEST(boost::fusion::at_key<int[3]>(seq)[1] == 42);
|
||||||
|
BOOST_TEST(boost::fusion::at_key<int[3]>(seq)[2] == 6);
|
||||||
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
using namespace boost::fusion;
|
using namespace boost::fusion;
|
||||||
@ -47,4 +80,7 @@ int main()
|
|||||||
test_at<deque<int[3]> >();
|
test_at<deque<int[3]> >();
|
||||||
test_at<list<int[3]> >();
|
test_at<list<int[3]> >();
|
||||||
test_at<tuple<int[3]> >();
|
test_at<tuple<int[3]> >();
|
||||||
|
|
||||||
|
test_at_key<set<int[3]> >();
|
||||||
|
test_at_key<map<pair<int[3], int[3]> > >();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user