From 652b741fa6325bf56d0e54ff906df3a8ecf0fabe Mon Sep 17 00:00:00 2001 From: joaquintides Date: Mon, 17 Apr 2023 18:22:56 +0200 Subject: [PATCH] Revert "Revert "added smart-pointer syntax to boost::flyweight (#11)"" This reverts commit e97cafcd4ab5ec138b779c564d85b8c36e14cacf. --- doc/reference/flyweight.html | 15 +++++++++++++-- doc/release_notes.html | 12 +++++++++++- doc/tutorial/basics.html | 26 +++++++++++++------------- example/basic.cpp | 9 ++++++--- example/html.cpp | 4 ++-- include/boost/flyweight/flyweight.hpp | 5 ++++- test/test_basic_template.hpp | 4 +++- 7 files changed, 52 insertions(+), 23 deletions(-) diff --git a/doc/reference/flyweight.html b/doc/reference/flyweight.html index e9b7644..6dad28d 100644 --- a/doc/reference/flyweight.html +++ b/doc/reference/flyweight.html @@ -298,7 +298,9 @@ objects constructed from equivalent keys. const key_type& get_key()const; const value_type& get()const; + const value_type& operator*()const; operator const value_type&()const; + const value_type* operator->()const; // modifiers: @@ -499,6 +501,7 @@ if KeyFromValue was not provided, nothrow. const value_type& get()const;
+ const value_type& operator*()const;
operator const value_type&()const;
@@ -507,6 +510,14 @@ object.
Exception safety: nothrow.
+const value_type* operator->()const + +
+Returns: The address of the value associated to the flyweight +object.
+Exception safety: nothrow. +
+

Modifiers

void swap(flyweight& x); @@ -784,9 +795,9 @@ Key-value flyweights
-

Revised March 15th 2020

+

Revised March 17th 2023

-

© Copyright 2006-2020 Joaquín M López Muñoz. +

© Copyright 2006-2023 Joaquín M López Muñoz. Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at diff --git a/doc/release_notes.html b/doc/release_notes.html index 35a04cc..3ebacf6 100644 --- a/doc/release_notes.html +++ b/doc/release_notes.html @@ -31,6 +31,7 @@ Acknowledgements

Contents

+

Boost 1.83 release

+ +

+

+

+

Boost 1.82 release

@@ -228,7 +238,7 @@ Acknowledgements
-

Revised February 26th 2023

+

Revised March 17th 2023

© Copyright 2006-2023 Joaquín M López Muñoz. Distributed under the Boost Software diff --git a/doc/tutorial/basics.html b/doc/tutorial/basics.html index 0e473be..6504c60 100644 --- a/doc/tutorial/basics.html +++ b/doc/tutorial/basics.html @@ -128,24 +128,24 @@ unchanged after the redefinition of user_entry:

Besides, flyweight<T> is convertible to -const T&, either implicitly or through the get -member function: +const T& implicitly, or explicitly using the get +member function. Smart-pointer syntax can also be used:

 std::string full_name(const user_entry& user)
 {
-  std::string full;
+std::string full;
 
-  full.reserve(
-    user.first_name.get().size()+   // get() returns the underlying
-    user.last_name.get().size()+1); // const std::string&
+full.reserve(
+user.first_name.get().size()+ // get() returns the underlying const std::string&
+user.last_name->size()+1);    // flyweights also work as pointers to their
+                              // underlying value
+full+=user.first_name;        // implicit conversion is used here
+full+=" ";
+full+=user.last_name;
 
-  full+=user.first_name;            // implicit conversion is used here
-  full+=" ";
-  full+=user.last_name;
-
-  return full;
+return full;
 }
 
@@ -257,9 +257,9 @@ Key-value flyweights
-

Revised April 24th 2019

+

Revised March 17th 2023

-

© Copyright 2006-2019 Joaquín M López Muñoz. +

© Copyright 2006-2023 Joaquín M López Muñoz. Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at diff --git a/example/basic.cpp b/example/basic.cpp index 286f735..0d88fa3 100644 --- a/example/basic.cpp +++ b/example/basic.cpp @@ -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 */ diff --git a/example/html.cpp b/example/html.cpp index 1fa6d34..e036b57 100644 --- a/example/html.cpp +++ b/example/html.cpp @@ -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; } diff --git a/include/boost/flyweight/flyweight.hpp b/include/boost/flyweight/flyweight.hpp index c00c168..ca0b483 100644 --- a/include/boost/flyweight/flyweight.hpp +++ b/include/boost/flyweight/flyweight.hpp @@ -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 /* keep it first to prevent nasty warns in MSVC */ #include +#include #include #include #include @@ -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 */ diff --git a/test/test_basic_template.hpp b/test/test_basic_template.hpp index 61b462b..bd6b171 100644 --- a/test/test_basic_template.hpp +++ b/test/test_basic_template.hpp @@ -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 */