]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/bimap/include/boost/bimap/tags/tagged.hpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / bimap / include / boost / bimap / tags / tagged.hpp
CommitLineData
7c673cae
FG
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/// \file tags/tagged.hpp
10/// \brief Defines the tagged class
11
12#ifndef BOOST_BIMAP_TAGS_TAGGED_HPP
13#define BOOST_BIMAP_TAGS_TAGGED_HPP
14
15#if defined(_MSC_VER)
16#pragma once
17#endif
18
19#include <boost/config.hpp>
20
21namespace boost {
22namespace bimaps {
23
24/// \brief A light non-invasive idiom to tag a type.
25/**
26
27There are a lot of ways of tagging a type. The standard library for example
28defines tags (empty structs) that are then inherited by the tagged class. To
29support built-in types and other types that simple cannot inherit from the
30tag, the standard builds another level of indirection. An example of this is
31the type_traits metafunction. This approach is useful if the tags are intended
32to be used in the library internals, and if the user does not have to create
33new tagged types often.
34
35Boost.MultiIndex is an example of a library that defines a tagged idiom that
36is better suited to the user. As an option, in the indexed by declaration
37of a multi-index container a user can \b attach a tag to each index, so it
38can be referred by it instead of by the index number. It is a very user
39friendly way of specifying a tag but is very invasive from the library writer's
40point of view. Each index must now support this additional parameter. Maybe
41not in the case of the multi-index container, but in simpler classes
42the information of the tags is used by the father class rather than by the
43tagged types.
44
45\b tagged is a light non-invasive idiom to tag a type. It is very intuitive
46and user-friendly. With the use of the defined metafunctions the library
47writer can enjoy the coding too.
48
49 **/
50
51namespace tags {
52
53/// \brief The tag holder
54/**
55
56The idea is to add a level of indirection to the type being tagged. With this
57class you wrapped a type and apply a tag to it. The only thing to remember is
58that if you write
59
60\code
61typedef tagged<type,tag> taggedType;
62\endcode
63
64Then instead to use directly the tagged type, in order to access it you have
65to write \c taggedType::value_type. The tag can be obtained using \c taggedType::tag.
66The idea is not to use this metadata directly but rather using the metafunctions
67that are defined in the support namespace. With this metafunctions you can work
68with tagged and untagged types in a consistent way. For example, the following
69code is valid:
70
71\code
72BOOST_STATIC_ASSERT( is_same< value_type_of<taggedType>, value_type_of<type> >::value );
73\endcode
74
75The are other useful metafunctions there too.
76See also value_type_of, tag_of, is_tagged, apply_to_value_type.
77
78\ingroup tagged_group
79 **/
80template< class Type, class Tag >
81struct tagged
82{
83 typedef Type value_type;
84 typedef Tag tag;
85};
86
87} // namespace tags
88} // namespace bimaps
89} // namespace boost
90
91/** \namespace boost::bimaps::tags::support
92\brief Metafunctions to work with tagged types.
93
94This metafunctions aims to make easier the manage of tagged types. They are all mpl
95compatible metafunctions and can be used with lambda expresions.
96The metafunction value_type_of and tag_of get the data in a tagged type in a secure
97and consistent way.
98default_tagged and overwrite_tagged allows to work with the tag of a tagged type,
99and apply_to_value_type is a higher order metafunction that allow the user to change
100the type of a TaggedType.
101 **/
102
103#endif // BOOST_BIMAP_TAGS_TAGGED_HPP
104
105
106
107