diff options
author | Anas Nashif <anas.nashif@intel.com> | 2013-08-26 08:15:55 -0400 |
---|---|---|
committer | Anas Nashif <anas.nashif@intel.com> | 2013-08-26 08:15:55 -0400 |
commit | bb4dd8289b351fae6b55e303f189127a394a1edd (patch) | |
tree | 77c9c35a31b1459dd7988c2448e797d142530c41 /libs/property_map | |
parent | 1a78a62555be32868418fe52f8e330c9d0f95d5a (diff) | |
download | boost-bb4dd8289b351fae6b55e303f189127a394a1edd.tar.gz boost-bb4dd8289b351fae6b55e303f189127a394a1edd.tar.bz2 boost-bb4dd8289b351fae6b55e303f189127a394a1edd.zip |
Imported Upstream version 1.51.0upstream/1.51.0
Diffstat (limited to 'libs/property_map')
-rw-r--r-- | libs/property_map/doc/LvaluePropertyMap.html | 14 | ||||
-rw-r--r-- | libs/property_map/doc/ReadablePropertyMap.html | 6 | ||||
-rw-r--r-- | libs/property_map/doc/function_property_map.html | 131 | ||||
-rw-r--r-- | libs/property_map/doc/identity_property_map.html | 75 | ||||
-rw-r--r-- | libs/property_map/doc/iterator_property_map.html | 8 | ||||
-rw-r--r-- | libs/property_map/doc/property_map.html | 8 | ||||
-rw-r--r-- | libs/property_map/doc/transform_value_property_map.html | 131 | ||||
-rw-r--r-- | libs/property_map/test/Jamfile.v2 | 2 | ||||
-rw-r--r-- | libs/property_map/test/function_property_map_test.cpp | 66 | ||||
-rw-r--r-- | libs/property_map/test/transform_value_property_map_test.cpp | 72 |
10 files changed, 466 insertions, 47 deletions
diff --git a/libs/property_map/doc/LvaluePropertyMap.html b/libs/property_map/doc/LvaluePropertyMap.html index be1c707907..9b75cc05e7 100644 --- a/libs/property_map/doc/LvaluePropertyMap.html +++ b/libs/property_map/doc/LvaluePropertyMap.html @@ -19,13 +19,9 @@ LvaluePropertyMap </H2> -The LvaluePropertyMap provides an interface for accessing a -reference to a property object (instead of a copy of the object as in -the <TT>get()</TT> function required by <a -href="./ReadablePropertyMap.html">ReadablePropertyMap</a>). An -LvaluePropertyMap can be <I>mutable</I> or -<I>non-mutable</I>. The mutable LvaluePropertyMap returns a -reference whereas the non-mutable returns a const reference. +The LvaluePropertyMap provides <code>operator[]</code> and function <code>get()</code> for accessing a +reference to a value object. The return type refines that of function <code>get()</code>in <a +href="./ReadablePropertyMap.html">ReadablePropertyMap</a>; it can only be a reference (for a <I>mutable</I> LvaluePropertyMap) or a const reference (for a <I>non-mutable</I> LvaluePropertyMap). <H3>Refinement of</H3> @@ -60,7 +56,7 @@ for non-mutable or <a href="./ReadWritePropertyMap.html">ReadWritePropertyMap</a <td><TT>boost::property_traits<PMap>::reference</TT></td> <td> The reference type, which must be a reference or const reference to -the value typeof the property map. +the value type of the property map. </td> </tr> @@ -90,7 +86,7 @@ The category of the property: a type convertible to <TT>value_type&</TT> for mutable, <TT>const value_type&</TT> otherwise. </TD> -<TD>Obtain a reference to the property identified by <TT>key</TT>.</TD> +<TD>Obtain a reference to the value associated with <TT>key</TT>.</TD> </TR> </TABLE> diff --git a/libs/property_map/doc/ReadablePropertyMap.html b/libs/property_map/doc/ReadablePropertyMap.html index c27a6c9a1f..368e0de7ff 100644 --- a/libs/property_map/doc/ReadablePropertyMap.html +++ b/libs/property_map/doc/ReadablePropertyMap.html @@ -20,8 +20,8 @@ Readable Property Map </H2> -A Readable Property Map provides read-access to the value object associated with a given key via a call to the <tt>get()</tt> function. -The <tt>get()</tt> function returns a copy of the value object. +A Readable Property Map provides read-access to the value associated with a given key via a call to the <tt>get()</tt> function. +The return type of the <tt>get()</tt>function is either the <tt>value_type</tt> of the property map or a (const or non-const) reference to that type. <h3>Refinement of</h3> @@ -95,7 +95,7 @@ The category of the property: a type convertible to <td>Get Property Value </td> <TD><TT>get(pmap, key)</TT></TD> <TD><TT>reference</TT></TD> -<TD>Lookup the property of the object identified by <TT>key</TT>.</TD> +<TD>Lookup the value associated with <TT>key</TT>.</TD> </TR> </TABLE> diff --git a/libs/property_map/doc/function_property_map.html b/libs/property_map/doc/function_property_map.html new file mode 100644 index 0000000000..4ab68b5123 --- /dev/null +++ b/libs/property_map/doc/function_property_map.html @@ -0,0 +1,131 @@ +<HTML> +<!-- + Copyright (c) 2012 Trustees of Indiana University + + 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) + --> +<Head> +<Title>Function Property Map Adaptor</Title> +<BODY BGCOLOR="#ffffff" LINK="#0000ee" TEXT="#000000" VLINK="#551a8b" + ALINK="#ff0000"> +<IMG SRC="../../../boost.png" + ALT="C++ Boost" width="277" height="86"> + +<BR Clear> + + +<H2><A NAME="sec:function-property-map"></A> +</h2> +<PRE> +function_property_map<UnaryFunction, Key, Ref> +</PRE> + +<P> +This property map is an adaptor that converts a function object into either a <a href="ReadablePropertyMap.html">Readable Property Map</a> or a <a href="LvaluePropertyMap.html">Lvalue Property Map</a>. The category of the property map is based on whether the function's return type (as given by <tt>Ref</tt>) is a non-const reference type. + +<P> + +<!-- <h3>Example</h3> + +<pre> +</pre> --> + +<H3>Where Defined</H3> + +<P> +<a href="../../../boost/property_map/function_property_map.hpp"><TT>boost/property_map/function_property_map.hpp</TT></a> + +<p> +<H3>Model Of</H3> + +<a href="./ReadablePropertyMap.html">Readable Property Map</a> or <a href="./LvaluePropertyMap.html">Lvalue Property Map</a> + +<P> + +<H3>Template Parameters</H3> + +<P> + +<TABLE border> +<TR> +<th>Parameter</th><th>Description</th><th>Default</th> +</tr> + + +<TR> +<TD><TT>UnaryFunction</TT></TD> +<TD>Must be a model of <a href="http://www.sgi.com/tech/stl/UnaryFunction.html">Unary Function</a> that accepts an object of type <tt>Key</tt> as an argument and returns a result of type <tt>Ref</tt>.</TD> +<TD> </td> +</tr> + +<TR> +<TD><TT>Key</TT></TD> <TD>The key type of the property map. +</TD> <TD> </TD> +</TR> + +<TR> +<TD><TT>Ref</TT></TD> +<TD>The result type of the function.</TD> +<TD><TT>boost::result_of<const UnaryFunction(const Key&)>::type</TT></TD> +</TR> + + +</TABLE> +<P> + +<H3>Members</H3> + +<P> +In addition to the methods and functions required by <a +href="./ReadablePropertyMap.html">Readable Property Map</a> or <a href="LvaluePropertyMap.html">Lvalue Property Map</a>, this +class has the following members: + +<hr> + +<pre> +property_traits<function_property_map>::value_type +</pre> +The type <tt>Ref</tt> with any reference or cv-qualifiers removed. + +<hr> + +<pre> +function_property_map(const UnaryFunction& f = UnaryFunction()) +</pre> +Constructor. + +<hr> + +<h3>Non-Member functions</h3> + +<hr> + +<pre> + template <class Key, class UnaryFunction> + function_property_map<UnaryFunction, Key> + make_function_property_map(const UnaryFunction& f); +</pre> +Returns a <tt>function_property_map</tt> using the given function and key type. + +<hr> + +<pre> + template <class Key, class Ref, class UnaryFunction> + function_property_map<UnaryFunction, Key, Ref> + make_function_property_map(const UnaryFunction& f); +</pre> +Returns a <tt>function_property_map</tt> using the given function and key and reference types. + +<hr> + +<br> +<HR> +<TABLE> +<TR valign=top> +<TD nowrap>Copyright © 2012</TD><TD>Trustees of Indiana University +</TD></TR></TABLE> + +</BODY> +</HTML> diff --git a/libs/property_map/doc/identity_property_map.html b/libs/property_map/doc/identity_property_map.html index 3a82ca2c8d..78e94a311b 100644 --- a/libs/property_map/doc/identity_property_map.html +++ b/libs/property_map/doc/identity_property_map.html @@ -1,6 +1,6 @@ <HTML> <!-- - Copyright (c) Jeremy Siek, Lie-Quan Lee, and Andrew Lumsdaine 2000 + Copyright (c) Jeremy Siek, Lie-Quan Lee, and Andrew Lumsdaine 2000, Alex Hagen-Zanker (2012) Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at @@ -9,30 +9,46 @@ <Head> <Title>Identity Property Map</Title> <BODY BGCOLOR="#ffffff" LINK="#0000ee" TEXT="#000000" VLINK="#551a8b" - ALINK="#ff0000"> + ALINK="#ff0000"> <IMG SRC="../../../boost.png" ALT="C++ Boost" width="277" height="86"> <BR Clear> -<H2><A NAME="sec:identity-property-map"></A> -</h2> +<H2><A NAME="sec:identity-property-map"></A> </h2> + <PRE> -identity_property_map +boost::typed_identity_property_map<T> + +typedef boost::typed_identity_propoperty_map<std::size_t> boost::identity_property_map </PRE> -This property map applies the identity function, that is, it just -returns a copy of the key object that was input. +<p>The <code>typed_identity_property_map</code> property map applies the identity function, that is, it just returns a copy of the key object that was input. The key and value types are both the same as the template parameter <code>T</code>. The <code>identity_property_map</code> name is for the common case where the key and value type are <code>std::size_t</code> (this name is deprecated for use within Boost.Graph). </p> +<p><em>Note:</em> Previously the function <code>get()</code> and <code>operator[]</code> for <code>identity_property_map</code> were overloaded to return a copy of keys of any type, i.e., not just <code>size_t</code>. These overloads are now deprecated, because they did not adhere to the property map concepts.</p> <H3>Where Defined</H3> <P> -<a href="../../../boost/property_map/property_map.hpp"><TT>boost/property_map/property_map.hpp</TT></a> - + <a href="../../../boost/property_map/property_map.hpp"><TT>boost/property_map/property_map.hpp</TT></a> +</P> + <h3>Model of</h3> <a href="./ReadablePropertyMap.html">Readable Property Map</a> +<h3>Template Parameters</h3> +<TABLE border> + <TR> + <th>Parameter</th> + <th>Description</th> + <th>Default</th> + </tr> + <TR> + <TD><TT>T</TT></TD> + <TD>Must be Copy Contructible</TD> + <TD> </td> + </tr> +</TABLE> <h3>Associated Types</h3> <table border> @@ -42,28 +58,34 @@ returns a copy of the key object that was input. <tr> <td><tt> -boost::property_traits<identity_property_map>::value_type +boost::property_traits<typed_identity_property_map<T> >::value_type </tt></td> <td> -This type is <tt>std::size_t</tt>; the map functions are templated. -</td> +This type is <tt>T</tt>. </td> </tr> <tr> <td><tt> -boost::property_traits<identity_property_map>::key_type +boost::property_traits<typed_identity_property_map<T> >::key_type </tt></td> <td> -This type is <tt>std::size_t</tt>; the map functions are templated. -</td> +This type is <tt>T</tt>.</td> +</tr> + +<tr> +<td><tt> +boost::property_traits<typed_identity_property_map<T> >::reference +</tt></td> +<td> +This type is <tt>T</tt>..</td> </tr> <tr> <td><tt> -boost::property_traits<identity_property_map>::category +boost::property_traits<typed_identity_property_map<T> >::category </tt></td> <td> -This type is <tt>boost::readable_op_bracket_tag</tt>. +This type is <tt>boost::readable_property_map_tag</tt>. </td> </tr> @@ -79,7 +101,7 @@ This type is <tt>boost::readable_op_bracket_tag</tt>. <tr> <td><tt> -identity_property_map() +typed_identity_property_map() </tt></td> <td> Default constructor. @@ -88,7 +110,7 @@ Default constructor. <tr> <td><tt> -identity_property_map(const identity_property_map& x) +typed_identity_property_map(const typed_identity_property_map<T>& x) </tt></td> <td> Copy constructor. @@ -97,8 +119,7 @@ Copy constructor. <tr> <td><tt> -template <class T><br> -T operator[](T x) const + T operator[](const T& x) const </tt></td> <td> Returns a copy of object <tt>x</tt>. @@ -115,9 +136,7 @@ Returns a copy of object <tt>x</tt>. </tr> <tr> -<td><tt> -template <class T><br> -T get(const identity_property_map& pmap, T x) +<td><tt> T get(const typed_identity_property_map<T>& pmap, const T& x) </tt></td> <td> Returns a copy of object <tt>x</tt>. @@ -131,15 +150,15 @@ Returns a copy of object <tt>x</tt>. <HR> <TABLE> <TR valign=top> -<TD nowrap>Copyright © 2000</TD><TD> +<TD nowrap>Copyright © 2000-2012</TD><TD> <a HREF="http://www.boost.org/people/jeremy_siek.htm">Jeremy Siek</a>, Univ.of Notre Dame (<A HREF="mailto:jsiek@lsc.nd.edu">jsiek@lsc.nd.edu</A>)<br> -<A HREF="http://www.boost.org/people/liequan_lee.htm">Lie-Quan Lee</A>, Univ.of Notre Dame (<A HREF="mailto:llee1@lsc.nd.edu">llee1@lsc.nd.edu</A>)<br> +<A HREF="http://www.boost.org/people/liequan_lee.htm">Lie-Quan Lee</A>, Univ. of Notre Dame (<A HREF="mailto:llee1@lsc.nd.edu">llee1@lsc.nd.edu</A>)<br> <A HREF="http://www.lsc.nd.edu/~lums">Andrew Lumsdaine</A>, Univ.of Notre Dame (<A -HREF="mailto:lums@lsc.nd.edu">lums@lsc.nd.edu</A>) -</TD></TR></TABLE> +HREF="mailto:lums@lsc.nd.edu">lums@lsc.nd.edu</A>)<br> +Alex Hagen-Zanker</TD></TR></TABLE> </BODY> </HTML> diff --git a/libs/property_map/doc/iterator_property_map.html b/libs/property_map/doc/iterator_property_map.html index 1806205fa9..5463289a39 100644 --- a/libs/property_map/doc/iterator_property_map.html +++ b/libs/property_map/doc/iterator_property_map.html @@ -175,12 +175,10 @@ Constructor. <hr> <pre> -reference operator[](difference_type v) const +reference operator[](const key_type& v) const </pre> -The operator bracket for property access. The <TT>reference</TT> and -<TT>difference_type</TT> types are from -<TT>std::iterator_traits<Iterator></TT>. - +The operator bracket for property access. The <TT>reference</TT> is from +<TT>std::iterator_traits<Iterator></TT> and the <tt>key_type</tt> is from <tt>boost::property_traits<OffsetMap></tt>. <hr> <h3>Non-Member functions</h3> diff --git a/libs/property_map/doc/property_map.html b/libs/property_map/doc/property_map.html index a77f01579c..197e4ffeaf 100644 --- a/libs/property_map/doc/property_map.html +++ b/libs/property_map/doc/property_map.html @@ -245,6 +245,7 @@ functions are defined in <tt><boost/property_map/property_map.hpp></tt>. struct property_traits { typedef typename PropertyMap::key_type key_type; typedef typename PropertyMap::value_type value_type; + typedef typename PropertyMap::reference reference; typedef typename PropertyMap::category category; }; @@ -268,6 +269,7 @@ functions are defined in <tt><boost/property_map/property_map.hpp></tt>. template <typename T> struct property_traits<T*> { typedef T value_type; + typedef T& reference; typedef std::ptrdiff_t key_type; typedef random_access_iterator_pa_tag category; }; @@ -281,13 +283,15 @@ functions are defined in <tt><boost/property_map/property_map.hpp></tt>. }</PRE> </li> - <li><a href="./identity_property_map.html">identity_property_map</a> </li> + <li><a href="./identity_property_map.html">identity_property_map and typed_identity_property_map</a> </li> + <li><a href="./function_property_map.html">function_property_map</a> </li> <li><a href="./iterator_property_map.html">iterator_property_map</a></li> <li><a href="./shared_array_property_map.html">shared_array_property_map</a></li> <li><a href="./associative_property_map.html">associative_property_map</a></li> <li><a href="./const_assoc_property_map.html">const_associative_property_map</a></li> <li><a href="./vector_property_map.html">vector_property_map</a></li> <li><a href="./ref_property_map.html">ref_property_map</a> </li> + <li><a href="./transform_value_property_map.html">transform_value_property_map</a> </li> </ul> <h3>History</h3> @@ -317,7 +321,7 @@ passed by value. <HR> <TABLE> <TR valign=top> -<TD nowrap>Copyright © 2000-2002</TD><TD> +<TD nowrap>Copyright © 2000-2002</TD><TD> <a HREF="http://www.boost.org/people/jeremy_siek.htm">Jeremy Siek</a>, Indiana University (<A HREF="mailto:jsiek@osl.iu.edu">jsiek@osl.iu.edu</A>) </TD></TR></TABLE> diff --git a/libs/property_map/doc/transform_value_property_map.html b/libs/property_map/doc/transform_value_property_map.html new file mode 100644 index 0000000000..ea4e7c0e20 --- /dev/null +++ b/libs/property_map/doc/transform_value_property_map.html @@ -0,0 +1,131 @@ +<HTML> +<!-- + Copyright (c) 2012 Trustees of Indiana University + + 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) + --> +<Head> +<Title>Value-Transforming Property Map Adaptor</Title> +<BODY BGCOLOR="#ffffff" LINK="#0000ee" TEXT="#000000" VLINK="#551a8b" + ALINK="#ff0000"> +<IMG SRC="../../../boost.png" + ALT="C++ Boost" width="277" height="86"> + +<BR Clear> + + +<H2><A NAME="sec:function-property-map"></A> +</h2> +<PRE> +transform_value_property_map<UnaryFunction, PM, Ref> +</PRE> + +<P> +This property map is an adaptor that composes a function object after an existing property map. The new property map will model either <a href="ReadablePropertyMap.html">Readable Property Map</a> or a <a href="LvaluePropertyMap.html">Lvalue Property Map</a>. The category of the property map is based on whether the function's return type (as given by <tt>Ref</tt>) is a non-const reference type. + +<P> + +<!-- <h3>Example</h3> + +<pre> +</pre> --> + +<H3>Where Defined</H3> + +<P> +<a href="../../../boost/property_map/transform_value_property_map.hpp"><TT>boost/property_map/transform_value_property_map.hpp</TT></a> + +<p> +<H3>Model Of</H3> + +<a href="./ReadablePropertyMap.html">Readable Property Map</a> or <a href="./LvaluePropertyMap.html">Lvalue Property Map</a> + +<P> + +<H3>Template Parameters</H3> + +<P> + +<TABLE border> +<TR> +<th>Parameter</th><th>Description</th><th>Default</th> +</tr> + + +<TR> +<TD><TT>UnaryFunction</TT></TD> +<TD>Must be a model of <a href="http://www.sgi.com/tech/stl/UnaryFunction.html">Unary Function</a> that accepts an object of type <tt>property_traits<PM>::reference</tt> as an argument and returns a result of type <tt>Ref</tt>.</TD> +<TD> </td> +</tr> + +<TR> +<TD><TT>PM</TT></TD> <TD>The underlying property map. +</TD> <TD> </TD> +</TR> + +<TR> +<TD><TT>Ref</TT></TD> +<TD>The result type of the function.</TD> +<TD><TT>boost::result_of<const UnaryFunction(property_traits<PM>::reference)>::type</TT></TD> +</TR> + + +</TABLE> +<P> + +<H3>Members</H3> + +<P> +In addition to the methods and functions required by <a +href="./ReadablePropertyMap.html">Readable Property Map</a> or <a href="LvaluePropertyMap.html">Lvalue Property Map</a>, this +class has the following members: + +<hr> + +<pre> +property_traits<transform_value_property_map>::value_type +</pre> +The type <tt>Ref</tt> with any reference or cv-qualifiers removed. + +<hr> + +<pre> +transform_value_property_map(const UnaryFunction& f, const PM& pm); +</pre> +Constructor. + +<hr> + +<h3>Non-Member functions</h3> + +<hr> + +<pre> + template <class PM, class UnaryFunction> + transform_value_property_map<UnaryFunction, PM> + make_transform_value_property_map(const UnaryFunction& f, const PM& pm); +</pre> +Returns a <tt>transform_value_property_map</tt> using the given function and property map type. + +<hr> + +<pre> + template <class Ref, class PM, class UnaryFunction> + transform_value_property_map<UnaryFunction, PM, Ref> + make_transform_value_property_map(const UnaryFunction& f, const PM& pm); +</pre> +Returns a <tt>transform_value_property_map</tt> using the given function and property map, explicitly giving the function's result type. + +<hr> + +<br> +<HR> +<TABLE> +<TR valign=top> +<TD nowrap>Copyright © 2012</TD><TD>Trustees of Indiana University +</TD></TR></TABLE> + +</BODY> +</HTML> diff --git a/libs/property_map/test/Jamfile.v2 b/libs/property_map/test/Jamfile.v2 index 68df4fe352..e989091a96 100644 --- a/libs/property_map/test/Jamfile.v2 +++ b/libs/property_map/test/Jamfile.v2 @@ -13,4 +13,6 @@ test-suite property_map : [ compile property_map_cc.cpp ] [ run dynamic_properties_test.cpp ] + [ run function_property_map_test.cpp ] + [ run transform_value_property_map_test.cpp ] ; diff --git a/libs/property_map/test/function_property_map_test.cpp b/libs/property_map/test/function_property_map_test.cpp new file mode 100644 index 0000000000..e5b0a2c713 --- /dev/null +++ b/libs/property_map/test/function_property_map_test.cpp @@ -0,0 +1,66 @@ +// +//======================================================================= +// Author: Jeremiah Willcock +// +// Copyright 2012, Trustees of Indiana University +// +// 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) +//======================================================================= +// + +#include <boost/property_map/function_property_map.hpp> +#include <boost/concept_check.hpp> +#include <boost/property_map/property_map.hpp> +#include <boost/test/minimal.hpp> +#include <boost/static_assert.hpp> + +template <typename T> +struct add1 {typedef T result_type; T operator()(const T& x) const {return x + 1;}}; + +template <typename T> +struct add1_val {typedef T result_type; T operator()(T x) const {return x + 1;}}; + +template <typename T> +struct return_fixed_ref { + int* ptr; + return_fixed_ref(int* ptr): ptr(ptr) {} + typedef int& result_type; + int& operator()(const T&) const {return *ptr;} +}; + +int test_main(int, char**) { + using namespace boost; + function_requires<ReadablePropertyMapConcept<function_property_map<add1<int>, int>, int> >(); + function_requires<ReadablePropertyMapConcept<function_property_map<add1<int>, int, double>, int> >(); + function_requires<ReadablePropertyMapConcept<function_property_map<add1_val<int>, int>, int> >(); + function_requires<ReadablePropertyMapConcept<function_property_map<add1_val<int>, int, double>, int> >(); + function_requires<ReadablePropertyMapConcept<function_property_map<return_fixed_ref<int>, int>, int> >(); + function_requires<WritablePropertyMapConcept<function_property_map<return_fixed_ref<int>, int>, int> >(); + function_requires<ReadWritePropertyMapConcept<function_property_map<return_fixed_ref<int>, int>, int> >(); + function_requires<LvaluePropertyMapConcept<function_property_map<return_fixed_ref<int>, int>, int> >(); + + BOOST_STATIC_ASSERT((boost::is_same<typename boost::property_traits<function_property_map<add1<int>, int> >::category, boost::readable_property_map_tag>::value)); + BOOST_STATIC_ASSERT((boost::is_same<typename boost::property_traits<function_property_map<add1_val<int>, int> >::category, boost::readable_property_map_tag>::value)); + BOOST_STATIC_ASSERT((boost::is_same<typename boost::property_traits<function_property_map<return_fixed_ref<int>, int> >::category, boost::lvalue_property_map_tag>::value)); + + BOOST_CHECK(get(function_property_map<add1<int>, int>(), 3) == 4); + BOOST_CHECK(get(function_property_map<add1<int>, int>(add1<int>()), 4) == 5); + BOOST_CHECK(get(make_function_property_map<int>(add1<int>()), 5) == 6); + BOOST_CHECK(get(function_property_map<add1_val<int>, int>(), 3) == 4); + BOOST_CHECK(get(function_property_map<add1_val<int>, int>(add1_val<int>()), 4) == 5); + BOOST_CHECK(get(make_function_property_map<int>(add1_val<int>()), 5) == 6); + int val; + const function_property_map<return_fixed_ref<int>, int> pm = return_fixed_ref<int>((&val)); + put(pm, 1, 6); + BOOST_CHECK(get(pm, 2) == 6); + BOOST_CHECK((get(pm, 3) = 7) == 7); + BOOST_CHECK(get(pm, 4) == 7); + const function_property_map<return_fixed_ref<int>, int> pm2 = pm; // Check shallow copying + BOOST_CHECK(get(pm2, 5) == 7); + put(pm2, 3, 1); + BOOST_CHECK(get(pm, 1) == 1); + + return 0; +} diff --git a/libs/property_map/test/transform_value_property_map_test.cpp b/libs/property_map/test/transform_value_property_map_test.cpp new file mode 100644 index 0000000000..296e1ba9f7 --- /dev/null +++ b/libs/property_map/test/transform_value_property_map_test.cpp @@ -0,0 +1,72 @@ +// +//======================================================================= +// Author: Jeremiah Willcock +// +// Copyright 2012, Trustees of Indiana University +// +// 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) +//======================================================================= +// + +#include <boost/property_map/function_property_map.hpp> +#include <boost/property_map/transform_value_property_map.hpp> +#include <boost/concept_check.hpp> +#include <boost/property_map/property_map.hpp> +#include <boost/test/minimal.hpp> +#include <boost/static_assert.hpp> + +// Ensure this is not default constructible +struct times2 {typedef int result_type; times2(int) {}; int operator()(int x) const {return 2 * x;}}; + +template <typename T> +struct add1 {typedef T result_type; T operator()(const T& x) const {return x + 1;}}; + +template <typename T> +struct add1_val {typedef T result_type; T operator()(T x) const {return x + 1;}}; + +template <typename T> +struct return_fixed_ref { + int* ptr; + return_fixed_ref(int* ptr): ptr(ptr) {} + typedef int& result_type; + int& operator()(const T&) const {return *ptr;} +}; + +int test_main(int, char**) { + using namespace boost; + typedef function_property_map<times2, int> PM; + PM orig_pm(times2(0)); + function_requires<ReadablePropertyMapConcept<transform_value_property_map<add1<int>, PM>, int> >(); + function_requires<ReadablePropertyMapConcept<transform_value_property_map<add1<int>, PM, double>, int> >(); + function_requires<ReadablePropertyMapConcept<transform_value_property_map<add1_val<int>, PM>, int> >(); + function_requires<ReadablePropertyMapConcept<transform_value_property_map<add1_val<int>, PM, double>, int> >(); + function_requires<ReadablePropertyMapConcept<transform_value_property_map<return_fixed_ref<int>, PM>, int> >(); + function_requires<WritablePropertyMapConcept<transform_value_property_map<return_fixed_ref<int>, PM>, int> >(); + function_requires<ReadWritePropertyMapConcept<transform_value_property_map<return_fixed_ref<int>, PM>, int> >(); + function_requires<LvaluePropertyMapConcept<transform_value_property_map<return_fixed_ref<int>, PM>, int> >(); + + BOOST_STATIC_ASSERT((boost::is_same<boost::property_traits<transform_value_property_map<add1<int>, PM> >::category, boost::readable_property_map_tag>::value)); + BOOST_STATIC_ASSERT((boost::is_same<boost::property_traits<transform_value_property_map<add1_val<int>, PM> >::category, boost::readable_property_map_tag>::value)); + BOOST_STATIC_ASSERT((boost::is_same<boost::property_traits<transform_value_property_map<return_fixed_ref<int>, PM> >::category, boost::lvalue_property_map_tag>::value)); + + BOOST_CHECK(get(transform_value_property_map<add1<int>, PM>(add1<int>(), orig_pm), 3) == 7); + BOOST_CHECK(get(transform_value_property_map<add1<int>, PM>(add1<int>(), orig_pm), 4) == 9); + BOOST_CHECK(get(make_transform_value_property_map(add1<int>(), orig_pm), 5) == 11); + BOOST_CHECK(get(transform_value_property_map<add1_val<int>, PM>(add1_val<int>(), orig_pm), 3) == 7); + BOOST_CHECK(get(transform_value_property_map<add1_val<int>, PM>(add1_val<int>(), orig_pm), 4) == 9); + BOOST_CHECK(get(make_transform_value_property_map<int>(add1_val<int>(), orig_pm), 5) == 11); + int val; + const transform_value_property_map<return_fixed_ref<int>, PM> pm(return_fixed_ref<int>((&val)), orig_pm); + put(pm, 1, 6); + BOOST_CHECK(get(pm, 2) == 6); + BOOST_CHECK((get(pm, 3) = 7) == 7); + BOOST_CHECK(get(pm, 4) == 7); + const transform_value_property_map<return_fixed_ref<int>, PM> pm2 = pm; // Check shallow copying + BOOST_CHECK(get(pm2, 5) == 7); + put(pm2, 3, 1); + BOOST_CHECK(get(pm, 1) == 1); + + return 0; +} |