Revert "Revert "added smart-pointer syntax to boost::flyweight (#11)""

This reverts commit e97cafcd4a.
This commit is contained in:
joaquintides
2023-04-17 18:22:56 +02:00
parent c2f1cfd540
commit 652b741fa6
7 changed files with 52 additions and 23 deletions

View File

@@ -298,7 +298,9 @@ objects constructed from equivalent keys.
<span class=keyword>const</span> <span class=identifier>key_type</span><span class=special>&amp;</span> <span class=identifier>get_key</span><span class=special>()</span><span class=keyword>const</span><span class=special>;</span>
<span class=keyword>const</span> <span class=identifier>value_type</span><span class=special>&amp;</span> <span class=identifier>get</span><span class=special>()</span><span class=keyword>const</span><span class=special>;</span>
<span class=keyword>const</span> <span class=identifier>value_type</span><span class=special>&amp;</span> <span class=keyword>operator</span><span class=special>*()</span><span class=keyword>const</span><span class=special>;</span>
<span class=keyword>operator</span> <span class=keyword>const</span> <span class=identifier>value_type</span><span class=special>&amp;()</span><span class=keyword>const</span><span class=special>;</span>
<span class=keyword>const</span> <span class=identifier>value_type</span><span class=special>*</span> <span class=keyword>operator</span><span class=special>-&gt;()</span><span class=keyword>const</span><span class=special>;</span>
<span class=comment>// modifiers:</span>
@@ -499,6 +501,7 @@ if <code>KeyFromValue</code> was not provided, <code>nothrow</code>.
</blockquote>
<code>const value_type&amp; get()const;<br>
const value_type&amp; operator*()const;<br>
operator const value_type&amp;()const;</code>
<blockquote>
@@ -507,6 +510,14 @@ object.<br>
<b>Exception safety:</b> <code>nothrow</code>.
</blockquote>
<code>const value_type* operator-&gt;()const</code>
<blockquote>
<b>Returns:</b> The address of the value associated to the <code>flyweight</code>
object.<br>
<b>Exception safety:</b> <code>nothrow</code>.
</blockquote>
<h4><a name="modifiers">Modifiers</a></h4>
<code>void swap(flyweight&amp; x);</code>
@@ -784,9 +795,9 @@ Key-value flyweights
<br>
<p>Revised March 15th 2020</p>
<p>Revised March 17th 2023</p>
<p>&copy; Copyright 2006-2020 Joaqu&iacute;n M L&oacute;pez Mu&ntilde;oz.
<p>&copy; Copyright 2006-2023 Joaqu&iacute;n M L&oacute;pez Mu&ntilde;oz.
Distributed under the Boost Software
License, Version 1.0. (See accompanying file <a href="../../../../LICENSE_1_0.txt">
LICENSE_1_0.txt</a> or copy at <a href="http://www.boost.org/LICENSE_1_0.txt">

View File

@@ -31,6 +31,7 @@ Acknowledgements
<h2>Contents</h2>
<ul>
<li><a href="#boost_1_83">Boost 1.83 release</a></li>
<li><a href="#boost_1_82">Boost 1.82 release</a></li>
<li><a href="#boost_1_81">Boost 1.81 release</a></li>
<li><a href="#boost_1_74">Boost 1.74 release</a></li>
@@ -49,6 +50,15 @@ Acknowledgements
<li><a href="#boost_1_38">Boost 1.38 release</a></li>
</ul>
<h2><a name="boost_1_83">Boost 1.83 release</a></h2>
<p>
<ul>
<li>Added smart-pointer syntax to <code>boost::flyweight</code> (<code>operator*</code>
and <code>operator-&gt;</code> dereferencing to the underlying value).</li>
</ul>
</p>
<h2><a name="boost_1_82">Boost 1.82 release</a></h2>
<p>
@@ -228,7 +238,7 @@ Acknowledgements
<br>
<p>Revised February 26th 2023</p>
<p>Revised March 17th 2023</p>
<p>&copy; Copyright 2006-2023 Joaqu&iacute;n M L&oacute;pez Mu&ntilde;oz.
Distributed under the Boost Software

View File

@@ -128,24 +128,24 @@ unchanged after the redefinition of <code>user_entry</code>:
<p>
Besides, <code>flyweight&lt;T&gt;</code> is convertible to
<code>const T&amp;</code>, either implicitly or through the <code>get</code>
member function:
<code>const T&amp;</code> implicitly, or explicitly using the <code>get</code>
member function. Smart-pointer syntax can also be used:
</p>
<blockquote><pre>
<span class=identifier>std</span><span class=special>::</span><span class=identifier>string</span> <span class=identifier>full_name</span><span class=special>(</span><span class=keyword>const</span> <span class=identifier>user_entry</span><span class=special>&amp;</span> <span class=identifier>user</span><span class=special>)</span>
<span class=special>{</span>
<span class=identifier>std</span><span class=special>::</span><span class=identifier>string</span> <span class=identifier>full</span><span class=special>;</span>
<span class=identifier>std</span><span class=special>::</span><span class=identifier>string</span> <span class=identifier>full</span><span class=special>;</span>
<span class=identifier>full</span><span class=special>.</span><span class=identifier>reserve</span><span class=special>(</span>
<span class=identifier>user</span><span class=special>.</span><span class=identifier>first_name</span><span class=special>.</span><span class=identifier>get</span><span class=special>().</span><span class=identifier>size</span><span class=special>()+</span> <span class=comment>// get() returns the underlying</span>
<span class=identifier>user</span><span class=special>.</span><span class=identifier>last_name</span><span class=special>.</span><span class=identifier>get</span><span class=special>().</span><span class=identifier>size</span><span class=special>()+</span><span class=number>1</span><span class=special>);</span> <span class=comment>// const std::string&amp;</span>
<span class=identifier>full</span><span class=special>.</span><span class=identifier>reserve</span><span class=special>(</span>
<span class=identifier>user</span><span class=special>.</span><span class=identifier>first_name</span><span class=special>.</span><span class=identifier>get</span><span class=special>().</span><span class=identifier>size</span><span class=special>()+</span> <span class=comment>// get() returns the underlying const std::string&amp;</span>
<span class=identifier>user</span><span class=special>.</span><span class=identifier>last_name</span><span class=special>-&gt;</span><span class=identifier>size</span><span class=special>()+</span><span class=number>1</span><span class=special>);</span> <span class=comment>// flyweights also work as pointers to their</span>
<span class=comment>// underlying value</span>
<span class=identifier>full</span><span class=special>+=</span><span class=identifier>user</span><span class=special>.</span><span class=identifier>first_name</span><span class=special>;</span> <span class=comment>// implicit conversion is used here</span>
<span class=identifier>full</span><span class=special>+=</span><span class=string>&quot; &quot;</span><span class=special>;</span>
<span class=identifier>full</span><span class=special>+=</span><span class=identifier>user</span><span class=special>.</span><span class=identifier>last_name</span><span class=special>;</span>
<span class=identifier>full</span><span class=special>+=</span><span class=identifier>user</span><span class=special>.</span><span class=identifier>first_name</span><span class=special>;</span> <span class=comment>// implicit conversion is used here</span>
<span class=identifier>full</span><span class=special>+=</span><span class=string>&quot; &quot;</span><span class=special>;</span>
<span class=identifier>full</span><span class=special>+=</span><span class=identifier>user</span><span class=special>.</span><span class=identifier>last_name</span><span class=special>;</span>
<span class=keyword>return</span> <span class=identifier>full</span><span class=special>;</span>
<span class=keyword>return</span> <span class=identifier>full</span><span class=special>;</span>
<span class=special>}</span>
</pre></blockquote>
@@ -257,9 +257,9 @@ Key-value flyweights
<br>
<p>Revised April 24th 2019</p>
<p>Revised March 17th 2023</p>
<p>&copy; Copyright 2006-2019 Joaqu&iacute;n M L&oacute;pez Mu&ntilde;oz.
<p>&copy; Copyright 2006-2023 Joaqu&iacute;n M L&oacute;pez Mu&ntilde;oz.
Distributed under the Boost Software
License, Version 1.0. (See accompanying file <a href="../../../../LICENSE_1_0.txt">
LICENSE_1_0.txt</a> or copy at <a href="http://www.boost.org/LICENSE_1_0.txt">

View File

@@ -1,6 +1,6 @@
/* Boost.Flyweight basic example.
*
* Copyright 2006-2020 Joaquin M Lopez Munoz.
* Copyright 2006-2023 Joaquin M Lopez Munoz.
* 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)
@@ -92,10 +92,13 @@ std::string full_name(const user_entry& user)
{
std::string full;
/* get() returns the underlying const std::string& */
/* get() returns the underlying const std::string&.
* Smart-pointer syntax can also be used.
*/
full.reserve(
user.first_name.get().size()+user.last_name.get().size()+1);
user.first_name.get().size()+ /* using get() */
user.last_name->size()+1); /* using operator-> */
/* here, on the other hand, implicit conversion is used */

View File

@@ -1,6 +1,6 @@
/* Boost.Flyweight example of flyweight-based formatted text processing.
*
* Copyright 2006-2014 Joaquin M Lopez Munoz.
* Copyright 2006-2023 Joaquin M Lopez Munoz.
* 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)
@@ -192,7 +192,7 @@ void scan_html(ForwardIterator first,ForwardIterator last,OutputIterator out)
for(html_context_data::reverse_iterator rit=context.rbegin();
rit!=context.rend();++rit){
if(rit->get().name==res.tag.get().name){
if(rit->get().name==res.tag->name){
context.erase(rit.base()-1,context.end());
break;
}

View File

@@ -1,6 +1,6 @@
/* Flyweight class.
*
* Copyright 2006-2022 Joaquin M Lopez Munoz.
* Copyright 2006-2023 Joaquin M Lopez Munoz.
* 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)
@@ -17,6 +17,7 @@
#include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
#include <algorithm>
#include <boost/core/addressof.hpp>
#include <boost/core/swap.hpp>
#include <boost/detail/workaround.hpp>
#include <boost/flyweight/detail/default_value_policy.hpp>
@@ -241,7 +242,9 @@ public:
const key_type& get_key()const{return core::key(h);}
const value_type& get()const{return core::value(h);}
const value_type& operator*()const{return get();}
operator const value_type&()const{return get();}
const value_type* operator->()const{return boost::addressof(get());}
/* exact type equality */

View File

@@ -1,6 +1,6 @@
/* Boost.Flyweight basic test template.
*
* Copyright 2006-2019 Joaquin M Lopez Munoz.
* Copyright 2006-2023 Joaquin M Lopez Munoz.
* 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)
@@ -87,10 +87,12 @@ void test_basic_template(
/* convertibility to underlying type */
BOOST_TEST(f1.get()==v1);
BOOST_TEST(*f1==v1);
/* identity of reference */
BOOST_TEST(&f1.get()==&c1.get());
BOOST_TEST(f1.operator->()==&c1.get());
/* modifiers */