1// Boost.Bimap
2//
3// Copyright (c) 2006-2007 Matias Capeletto
4//
5// Distributed under the Boost Software License, Version 1.0.
6// (See accompanying file LICENSE_1_0.txt or copy at
7// http://www.boost.org/LICENSE_1_0.txt)
8
9// VC++ 8.0 warns on usage of certain Standard Library and API functions that
10// can be cause buffer overruns or other possible security issues if misused.
11// See https://web.archive.org/web/20071014014301/http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/default.aspx
12// But the wording of the warning is misleading and unsettling, there are no
13// portable alternative functions, and VC++ 8.0's own libraries use the
14// functions in question. So turn off the warnings.
15#define _CRT_SECURE_NO_DEPRECATE
16#define _SCL_SECURE_NO_DEPRECATE
17
18#include <boost/config.hpp>
19
20#include <boost/core/lightweight_test.hpp>
21
22#include <boost/static_assert.hpp>
23
24// Boost.MPL
25#include <boost/type_traits/is_same.hpp>
26#include <boost/mpl/placeholders.hpp>
27#include <boost/mpl/assert.hpp>
28#include <boost/type_traits/add_const.hpp>
29
30// Boost.Bimap
31#include <boost/bimap/detail/test/check_metadata.hpp>
32
33// Boost.Bimap.Tags
34#include <boost/bimap/tags/tagged.hpp>
35#include <boost/bimap/tags/support/default_tagged.hpp>
36#include <boost/bimap/tags/support/is_tagged.hpp>
37#include <boost/bimap/tags/support/overwrite_tagged.hpp>
38#include <boost/bimap/tags/support/tag_of.hpp>
39#include <boost/bimap/tags/support/value_type_of.hpp>
40#include <boost/bimap/tags/support/apply_to_value_type.hpp>
41
42
43
44
45BOOST_BIMAP_TEST_STATIC_FUNCTION( test_metafunctions )
46{
47 using namespace boost::bimaps::tags::support;
48 using namespace boost::bimaps::tags;
49 using namespace boost::mpl::placeholders;
50 using namespace boost;
51
52 struct tag {};
53 struct value {};
54
55 // Test apply_to_value_type metafunction
56 // tagged<value,tag> ----(add_const<_>)----> tagged<value const,tag>
57 typedef tagged< value, tag > ttype;
58 typedef apply_to_value_type< add_const<_>,ttype>::type result;
59 typedef is_same<tagged<value const,tag>,result> compare;
60 BOOST_MPL_ASSERT_MSG(compare::value,tag,(result));
61}
62
63struct tag_a {};
64struct tag_b {};
65struct data {};
66
67void test_function()
68{
69
70 using namespace boost::bimaps::tags::support;
71 using namespace boost::bimaps::tags;
72 using boost::is_same;
73
74 typedef tagged< data, tag_a > data_a;
75 typedef tagged< data, tag_b > data_b;
76
77 BOOST_TEST(( is_same< data_a::value_type , data >::value ));
78 BOOST_TEST(( is_same< data_a::tag , tag_a >::value ));
79
80 BOOST_TEST((
81 is_same< overwrite_tagged < data_a, tag_b >::type, data_b >::value
82 ));
83 BOOST_TEST((
84 is_same< default_tagged < data_a, tag_b >::type, data_a >::value
85 ));
86 BOOST_TEST((
87 is_same< default_tagged < data , tag_b >::type, data_b >::value
88 ));
89
90 BOOST_TEST(( is_tagged< data >::value == false ));
91 BOOST_TEST(( is_tagged< data_a >::value == true ));
92
93 BOOST_TEST(( is_same< value_type_of<data_a>::type, data >::value ));
94 BOOST_TEST(( is_same< tag_of <data_a>::type, tag_a >::value ));
95
96}
97
98int main()
99{
100 test_function();
101
102 // Test metanfunctions
103 BOOST_BIMAP_CALL_TEST_STATIC_FUNCTION( test_metafunctions );
104
105 return boost::report_errors();
106}
107
108

source code of boost/libs/bimap/test/test_tagged.cpp