From 1a78a62555be32868418fe52f8e330c9d0f95d5a Mon Sep 17 00:00:00 2001 From: Anas Nashif Date: Tue, 30 Oct 2012 12:57:26 -0700 Subject: Imported Upstream version 1.49.0 --- boost/bimap/tags/support/apply_to_value_type.hpp | 70 +++++++++++++++ boost/bimap/tags/support/default_tagged.hpp | 73 ++++++++++++++++ boost/bimap/tags/support/is_tagged.hpp | 64 ++++++++++++++ boost/bimap/tags/support/overwrite_tagged.hpp | 73 ++++++++++++++++ boost/bimap/tags/support/tag_of.hpp | 75 ++++++++++++++++ boost/bimap/tags/support/value_type_of.hpp | 74 ++++++++++++++++ boost/bimap/tags/tagged.hpp | 107 +++++++++++++++++++++++ 7 files changed, 536 insertions(+) create mode 100644 boost/bimap/tags/support/apply_to_value_type.hpp create mode 100644 boost/bimap/tags/support/default_tagged.hpp create mode 100644 boost/bimap/tags/support/is_tagged.hpp create mode 100644 boost/bimap/tags/support/overwrite_tagged.hpp create mode 100644 boost/bimap/tags/support/tag_of.hpp create mode 100644 boost/bimap/tags/support/value_type_of.hpp create mode 100644 boost/bimap/tags/tagged.hpp (limited to 'boost/bimap/tags') diff --git a/boost/bimap/tags/support/apply_to_value_type.hpp b/boost/bimap/tags/support/apply_to_value_type.hpp new file mode 100644 index 0000000000..bb6aa60613 --- /dev/null +++ b/boost/bimap/tags/support/apply_to_value_type.hpp @@ -0,0 +1,70 @@ +// Boost.Bimap +// +// Copyright (c) 2006-2007 Matias Capeletto +// +// 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 tags/support/apply_to_value_type.hpp +/// \brief Similar to mpl::apply but for tagged types. + +#ifndef BOOST_BIMAP_TAGS_SUPPORT_APPLY_TO_VALUE_TYPE_HPP +#define BOOST_BIMAP_TAGS_SUPPORT_APPLY_TO_VALUE_TYPE_HPP + +#if defined(_MSC_VER) && (_MSC_VER>=1200) +#pragma once +#endif + +#include + +#include +#include + +/** \struct boost::bimaps::tags::support::apply_to_value_type +\brief Higger order metafunction similar to mpl::apply but for tagged types. + +\code +template< class Metafunction, class TaggedType > +struct apply_to_value_type +{ + typedef tagged + < + Metafuntion< value_type_of< TaggedType >::type >::type, + tag_of< TaggedType >::type + + > type; +}; +\endcode + +This higher order metafunctions is very useful, and it can be used with lambda +expresions. + +See also tagged. + **/ + +#ifndef BOOST_BIMAP_DOXYGEN_WILL_NOT_PROCESS_THE_FOLLOWING_LINES + +namespace boost { +namespace bimaps { +namespace tags { +namespace support { + +template < class F, class TaggedType > +struct apply_to_value_type; + +template < class F, class ValueType, class Tag > +struct apply_to_value_type > +{ + typedef BOOST_DEDUCED_TYPENAME mpl::apply< F, ValueType >::type new_value_type; + typedef tagged< new_value_type, Tag > type; +}; + +} // namespace support +} // namespace tags +} // namespace bimaps +} // namespace boost + +#endif // BOOST_BIMAP_DOXYGEN_WILL_NOT_PROCESS_THE_FOLLOWING_LINES + +#endif // BOOST_BIMAP_TAGS_SUPPORT_APPLY_TO_VALUE_TYPE_HPP diff --git a/boost/bimap/tags/support/default_tagged.hpp b/boost/bimap/tags/support/default_tagged.hpp new file mode 100644 index 0000000000..4c02a65952 --- /dev/null +++ b/boost/bimap/tags/support/default_tagged.hpp @@ -0,0 +1,73 @@ +// Boost.Bimap +// +// Copyright (c) 2006-2007 Matias Capeletto +// +// 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 tags/support/default_tagged.hpp +/// \brief Weak tagging + +#ifndef BOOST_BIMAP_TAGS_SUPPORT_DEFAULT_TAGGED_HPP +#define BOOST_BIMAP_TAGS_SUPPORT_DEFAULT_TAGGED_HPP + +#if defined(_MSC_VER) && (_MSC_VER>=1200) +#pragma once +#endif + +#include + +#include + +/** \struct boost::bimaps::tags::support::default_tagged +\brief Weak tagging metafunction + +\code +template< class Type, class Tag > +struct default_tagged +{ + typedef {TaggedType} type; +}; +\endcode + +If the type is not tagged, this metafunction returns a tagged type with the +default tag. If it is tagged, the returns the type unchanged. + +See also tagged, overwrite_tagged. + **/ + +#ifndef BOOST_BIMAP_DOXYGEN_WILL_NOT_PROCESS_THE_FOLLOWING_LINES + +namespace boost { +namespace bimaps { +namespace tags { +namespace support { + + +// Default Tagging +// A metafunction that create a tagged type with a default tag value. + +template< class Type, class DefaultTag > +struct default_tagged +{ + typedef tagged type; +}; + +template< class Type, class OldTag, class NewTag > +struct default_tagged< tagged< Type, OldTag >, NewTag > +{ + typedef tagged type; +}; + +} // namespace support +} // namespace tags +} // namespace bimaps +} // namespace boost + +#endif // BOOST_BIMAP_DOXYGEN_WILL_NOT_PROCESS_THE_FOLLOWING_LINES + +#endif // BOOST_BIMAP_TAGS_SUPPORT_DEFAULT_TAGGED_HPP + + + diff --git a/boost/bimap/tags/support/is_tagged.hpp b/boost/bimap/tags/support/is_tagged.hpp new file mode 100644 index 0000000000..892b3b1022 --- /dev/null +++ b/boost/bimap/tags/support/is_tagged.hpp @@ -0,0 +1,64 @@ +// Boost.Bimap +// +// Copyright (c) 2006-2007 Matias Capeletto +// +// 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 tags/support/is_tagged.hpp +/// \brief type_traits extension + +#ifndef BOOST_BIMAP_TAGS_SUPPORT_IS_TAGGED_HPP +#define BOOST_BIMAP_TAGS_SUPPORT_IS_TAGGED_HPP + +#if defined(_MSC_VER) && (_MSC_VER>=1200) +#pragma once +#endif + +#include + +#include +#include + +/** \struct boost::bimaps::tags::support::is_tagged +\brief Type trait to check if a type is tagged. + +\code +template< class Type > +struct is_tagged +{ + typedef {mpl::true_/mpl::false_} type; +}; +\endcode + +See also tagged. + **/ + +#ifndef BOOST_BIMAP_DOXYGEN_WILL_NOT_PROCESS_THE_FOLLOWING_LINES + +namespace boost { +namespace bimaps { +namespace tags { +namespace support { + + +// is_tagged metafunction + +template< class Type > +struct is_tagged : + ::boost::mpl::false_ {}; + +template< class Type, class Tag > +struct is_tagged< tagged< Type, Tag > > : + ::boost::mpl::true_ {}; + +} // namespace support +} // namespace tags +} // namespace bimaps +} // namespace boost + +#endif // BOOST_BIMAP_DOXYGEN_WILL_NOT_PROCESS_THE_FOLLOWING_LINES + +#endif // BOOST_BIMAP_TAGS_SUPPORT_IS_TAGGED_HPP + diff --git a/boost/bimap/tags/support/overwrite_tagged.hpp b/boost/bimap/tags/support/overwrite_tagged.hpp new file mode 100644 index 0000000000..55cd0fc8e4 --- /dev/null +++ b/boost/bimap/tags/support/overwrite_tagged.hpp @@ -0,0 +1,73 @@ +// Boost.Bimap +// +// Copyright (c) 2006-2007 Matias Capeletto +// +// 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 tags/support/overwrite_tagged.hpp +/// \brief Hard tagging + +#ifndef BOOST_BIMAP_TAGS_SUPPORT_OVERWRITE_TAGGED_HPP +#define BOOST_BIMAP_TAGS_SUPPORT_OVERWRITE_TAGGED_HPP + +#if defined(_MSC_VER) && (_MSC_VER>=1200) +#pragma once +#endif + +#include + +#include + +/** \struct boost::bimaps::tags::support::overwrite_tagged +\brief Hard tagging metafunction + +\code +template< class Type, class Tag > +struct overwrite_tagged +{ + typedef {TaggedType} type; +}; +\endcode + +If the type is not tagged, this metafunction returns a tagged type with the +passed tag. If it is tagged it returns a new tagged type with the tag replaced +by the one passed as a parameter. + +See also tagged, default_tagged. + **/ + +#ifndef BOOST_BIMAP_DOXYGEN_WILL_NOT_PROCESS_THE_FOLLOWING_LINES + +namespace boost { +namespace bimaps { +namespace tags { +namespace support { + + +// Change the tag + +template< class Type, class NewTag > +struct overwrite_tagged +{ + typedef tagged type; +}; + +template< class Type, class OldTag, class NewTag > +struct overwrite_tagged< tagged< Type, OldTag >, NewTag > +{ + typedef tagged type; +}; + + +} // namespace support +} // namespace tags +} // namespace bimaps +} // namespace boost + +#endif // BOOST_BIMAP_DOXYGEN_WILL_NOT_PROCESS_THE_FOLLOWING_LINES + +#endif // BOOST_BIMAP_TAGS_SUPPORT_OVERWRITE_TAGGED_HPP + + diff --git a/boost/bimap/tags/support/tag_of.hpp b/boost/bimap/tags/support/tag_of.hpp new file mode 100644 index 0000000000..413703b41c --- /dev/null +++ b/boost/bimap/tags/support/tag_of.hpp @@ -0,0 +1,75 @@ +// Boost.Bimap +// +// Copyright (c) 2006-2007 Matias Capeletto +// +// 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 tags/support/tag_of.hpp +/// \brief Safe way to acces the tag of a type + +#ifndef BOOST_BIMAP_TAGS_SUPPORT_TAG_OF_HPP +#define BOOST_BIMAP_TAGS_SUPPORT_TAG_OF_HPP + +#if defined(_MSC_VER) && (_MSC_VER>=1200) +#pragma once +#endif + +#include + +#include +#include + +/** \struct boost::bimaps::tags::support::tag_of +\brief Metafunction to obtain the tag of a type. + +\code +template< class TaggedType > +struct tag_of +{ + typedef {Tag} type; +}; +\endcode + +If the type is not tagged you will get a compile timer error with the following message: + +\verbatim +USING_TAG_OF_WITH_AN_UNTAGGED_TYPE, TaggedType +\endverbatim + +See also tagged, value_type_of. + **/ + +#ifndef BOOST_BIMAP_DOXYGEN_WILL_NOT_PROCESS_THE_FOLLOWING_LINES + +namespace boost { +namespace bimaps { +namespace tags { +namespace support { + + +// tag_of metafunction + +template< class Type > +struct tag_of +{ + BOOST_BIMAP_STATIC_ERROR( USING_TAG_OF_WITH_AN_UNTAGGED_TYPE, (Type) ); +}; + +template< class Type, class Tag > +struct tag_of< tagged< Type, Tag > > +{ + typedef Tag type; +}; + + +} // namespace support +} // namespace tags +} // namespace bimaps +} // namespace boost + +#endif // BOOST_BIMAP_DOXYGEN_WILL_NOT_PROCESS_THE_FOLLOWING_LINES + +#endif // BOOST_BIMAP_TAGS_SUPPORT_TAG_OF_HPP + diff --git a/boost/bimap/tags/support/value_type_of.hpp b/boost/bimap/tags/support/value_type_of.hpp new file mode 100644 index 0000000000..a4ea82814c --- /dev/null +++ b/boost/bimap/tags/support/value_type_of.hpp @@ -0,0 +1,74 @@ +// Boost.Bimap +// +// Copyright (c) 2006-2007 Matias Capeletto +// +// 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 tags/support/value_type_of.hpp +/// \brief Consistent way to access the value type of a tagged or untagged type. + +#ifndef BOOST_BIMAP_TAGS_SUPPORT_VALUE_TYPE_OF_HPP +#define BOOST_BIMAP_TAGS_SUPPORT_VALUE_TYPE_OF_HPP + +#if defined(_MSC_VER) && (_MSC_VER>=1200) +#pragma once +#endif + +#include + +#include + +/** \struct boost::bimaps::tags::support::value_type_of +\brief Metafunction to work with tagged and untagged type uniformly + +\code +template< class Type > +struct value_type_of +{ + typedef {UntaggedType} type; +}; +\endcode + +If the type is tagged this metafunction returns Type::value_type, and if it is not +tagged it return the same type. This allows to work consistenly with tagged and +untagged types. + +See also tagged, tag_of. + **/ + +#ifndef BOOST_BIMAP_DOXYGEN_WILL_NOT_PROCESS_THE_FOLLOWING_LINES + + +namespace boost { +namespace bimaps { +namespace tags { +namespace support { + + +// value_type_of metafunction + +template< class Type > +struct value_type_of +{ + typedef Type type; +}; + +template< class Type, class Tag > +struct value_type_of< tagged< Type, Tag > > +{ + typedef Type type; +}; + + +} // namespace support +} // namespace tags +} // namespace bimaps +} // namespace boost + +#endif // BOOST_BIMAP_DOXYGEN_WILL_NOT_PROCESS_THE_FOLLOWING_LINES + +#endif // BOOST_BIMAP_TAGS_SUPPORT_VALUE_TYPE_OF_HPP + + diff --git a/boost/bimap/tags/tagged.hpp b/boost/bimap/tags/tagged.hpp new file mode 100644 index 0000000000..ca2a24c2f9 --- /dev/null +++ b/boost/bimap/tags/tagged.hpp @@ -0,0 +1,107 @@ +// Boost.Bimap +// +// Copyright (c) 2006-2007 Matias Capeletto +// +// 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 tags/tagged.hpp +/// \brief Defines the tagged class + +#ifndef BOOST_BIMAP_TAGS_TAGGED_HPP +#define BOOST_BIMAP_TAGS_TAGGED_HPP + +#if defined(_MSC_VER) && (_MSC_VER>=1200) +#pragma once +#endif + +#include + +namespace boost { +namespace bimaps { + +/// \brief A light non-invasive idiom to tag a type. +/** + +There are a lot of ways of tagging a type. The standard library for example +defines tags (empty structs) that are then inherited by the tagged class. To +support built-in types and other types that simple cannot inherit from the +tag, the standard builds another level of indirection. An example of this is +the type_traits metafunction. This approach is useful if the tags are intended +to be used in the library internals, and if the user does not have to create +new tagged types often. + +Boost.MultiIndex is an example of a library that defines a tagged idiom that +is better suited to the user. As an option, in the indexed by declaration +of a multi-index container a user can \b attach a tag to each index, so it +can be referred by it instead of by the index number. It is a very user +friendly way of specifying a tag but is very invasive from the library writer's +point of view. Each index must now support this additional parameter. Maybe +not in the case of the multi-index container, but in simpler classes +the information of the tags is used by the father class rather than by the +tagged types. + +\b tagged is a light non-invasive idiom to tag a type. It is very intuitive +and user-friendly. With the use of the defined metafunctions the library +writer can enjoy the coding too. + + **/ + +namespace tags { + +/// \brief The tag holder +/** + +The idea is to add a level of indirection to the type being tagged. With this +class you wrapped a type and apply a tag to it. The only thing to remember is +that if you write + +\code +typedef tagged taggedType; +\endcode + +Then instead to use directly the tagged type, in order to access it you have +to write \c taggedType::value_type. The tag can be obtained using \c taggedType::tag. +The idea is not to use this metadata directly but rather using the metafunctions +that are defined in the support namespace. With this metafunctions you can work +with tagged and untagged types in a consistent way. For example, the following +code is valid: + +\code +BOOST_STATIC_ASSERT( is_same< value_type_of, value_type_of >::value ); +\endcode + +The are other useful metafunctions there too. +See also value_type_of, tag_of, is_tagged, apply_to_value_type. + +\ingroup tagged_group + **/ +template< class Type, class Tag > +struct tagged +{ + typedef Type value_type; + typedef Tag tag; +}; + +} // namespace tags +} // namespace bimaps +} // namespace boost + +/** \namespace boost::bimaps::tags::support +\brief Metafunctions to work with tagged types. + +This metafunctions aims to make easier the manage of tagged types. They are all mpl +compatible metafunctions and can be used with lambda expresions. +The metafunction value_type_of and tag_of get the data in a tagged type in a secure +and consistent way. +default_tagged and overwrite_tagged allows to work with the tag of a tagged type, +and apply_to_value_type is a higher order metafunction that allow the user to change +the type of a TaggedType. + **/ + +#endif // BOOST_BIMAP_TAGS_TAGGED_HPP + + + + -- cgit v1.2.3