1 | //
|
---|
2 | //=======================================================================
|
---|
3 | // Author: Jeremiah Willcock
|
---|
4 | //
|
---|
5 | // Copyright 2012, Trustees of Indiana University
|
---|
6 | //
|
---|
7 | // Distributed under the Boost Software License, Version 1.0. (See
|
---|
8 | // accompanying file LICENSE_1_0.txt or copy at
|
---|
9 | // http://www.boost.org/LICENSE_1_0.txt)
|
---|
10 | //=======================================================================
|
---|
11 | //
|
---|
12 |
|
---|
13 | #include <boost/property_map/function_property_map.hpp>
|
---|
14 | #include <boost/concept_check.hpp>
|
---|
15 | #include <boost/property_map/property_map.hpp>
|
---|
16 | #include <boost/test/minimal.hpp>
|
---|
17 |
|
---|
18 | template <typename T>
|
---|
19 | struct add1 {typedef T result_type; T operator()(const T& x) const {return x + 1;}};
|
---|
20 |
|
---|
21 | template <typename T>
|
---|
22 | struct return_fixed_ref {
|
---|
23 | int* ptr;
|
---|
24 | return_fixed_ref(int* ptr): ptr(ptr) {}
|
---|
25 | typedef int& result_type;
|
---|
26 | int& operator()(const T&) const {return *ptr;}
|
---|
27 | };
|
---|
28 |
|
---|
29 | int test_main(int, char**) {
|
---|
30 | using namespace boost;
|
---|
31 | function_requires<ReadablePropertyMapConcept<function_property_map<add1<int>, int>, int> >();
|
---|
32 | function_requires<ReadablePropertyMapConcept<function_property_map<add1<int>, int, double>, int> >();
|
---|
33 | function_requires<ReadablePropertyMapConcept<function_property_map<return_fixed_ref<int>, int>, int> >();
|
---|
34 | function_requires<WritablePropertyMapConcept<function_property_map<return_fixed_ref<int>, int>, int> >();
|
---|
35 | function_requires<ReadWritePropertyMapConcept<function_property_map<return_fixed_ref<int>, int>, int> >();
|
---|
36 | function_requires<LvaluePropertyMapConcept<function_property_map<return_fixed_ref<int>, int>, int> >();
|
---|
37 |
|
---|
38 | BOOST_CHECK(get(function_property_map<add1<int>, int>(), 3) == 4);
|
---|
39 | BOOST_CHECK(get(function_property_map<add1<int>, int>(add1<int>()), 4) == 5);
|
---|
40 | BOOST_CHECK(get(make_function_property_map<int>(add1<int>()), 5) == 6);
|
---|
41 | int val;
|
---|
42 | const function_property_map<return_fixed_ref<int>, int> pm = return_fixed_ref<int>((&val));
|
---|
43 | put(pm, 1, 6);
|
---|
44 | BOOST_CHECK(get(pm, 2) == 6);
|
---|
45 | BOOST_CHECK((get(pm, 3) = 7) == 7);
|
---|
46 | BOOST_CHECK(get(pm, 4) == 7);
|
---|
47 | const function_property_map<return_fixed_ref<int>, int> pm2 = pm; // Check shallow copying
|
---|
48 | BOOST_CHECK(get(pm2, 5) == 7);
|
---|
49 | put(pm2, 3, 1);
|
---|
50 | BOOST_CHECK(get(pm, 1) == 1);
|
---|
51 |
|
---|
52 | return 0;
|
---|
53 | }
|
---|