From 21457c16236dc8afa0c3c387818e49aece088dcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reimar=20D=C3=B6ffinger?= Date: Tue, 1 Feb 2022 21:16:03 +0100 Subject: [PATCH] Add "const" versions of -> and * operators. Also for the "component" and "obj" functions these use. Fixes issue #134. --- include/boost/iostreams/code_converter.hpp | 2 ++ include/boost/iostreams/detail/adapter/concept_adapter.hpp | 2 ++ include/boost/iostreams/detail/adapter/device_adapter.hpp | 1 + include/boost/iostreams/detail/adapter/direct_adapter.hpp | 2 ++ include/boost/iostreams/detail/adapter/filter_adapter.hpp | 1 + .../iostreams/detail/broken_overload_resolution/stream.hpp | 2 ++ .../detail/broken_overload_resolution/stream_buffer.hpp | 2 ++ include/boost/iostreams/detail/streambuf/direct_streambuf.hpp | 1 + .../boost/iostreams/detail/streambuf/indirect_streambuf.hpp | 2 ++ include/boost/iostreams/stream.hpp | 3 +++ include/boost/iostreams/stream_buffer.hpp | 2 ++ 11 files changed, 20 insertions(+) diff --git a/include/boost/iostreams/code_converter.hpp b/include/boost/iostreams/code_converter.hpp index 0bac461d4..0cb357f17 100644 --- a/include/boost/iostreams/code_converter.hpp +++ b/include/boost/iostreams/code_converter.hpp @@ -283,7 +283,9 @@ class code_converter // Direct device access. Device& operator*() { return detail::unwrap_direct(dev()); } + const Device& operator*() const { return detail::unwrap_direct(dev()); } Device* operator->() { return &detail::unwrap_direct(dev()); } + const Device* operator->() const { return &detail::unwrap_direct(dev()); } private: template // Used for forwarding. void open_impl(const T& t BOOST_IOSTREAMS_CONVERTER_PARAMS()) diff --git a/include/boost/iostreams/detail/adapter/concept_adapter.hpp b/include/boost/iostreams/detail/adapter/concept_adapter.hpp index 3a76b3fb3..875d8d5cd 100644 --- a/include/boost/iostreams/detail/adapter/concept_adapter.hpp +++ b/include/boost/iostreams/detail/adapter/concept_adapter.hpp @@ -68,7 +68,9 @@ class concept_adapter { { BOOST_STATIC_ASSERT(!is_std_io::value); } T& operator*() { return t_; } + const T& operator*() const { return t_; } T* operator->() { return &t_; } + const T* operator->() const { return &t_; } std::streamsize read(char_type* s, std::streamsize n) { return this->read(s, n, (basic_null_source*) 0); } diff --git a/include/boost/iostreams/detail/adapter/device_adapter.hpp b/include/boost/iostreams/detail/adapter/device_adapter.hpp index 9dd723a0f..9f9f214e0 100644 --- a/include/boost/iostreams/detail/adapter/device_adapter.hpp +++ b/include/boost/iostreams/detail/adapter/device_adapter.hpp @@ -35,6 +35,7 @@ class device_adapter { public: explicit device_adapter(param_type t) : t_(t) { } T& component() { return t_; } + const T& component() const { return t_; } void close() { diff --git a/include/boost/iostreams/detail/adapter/direct_adapter.hpp b/include/boost/iostreams/detail/adapter/direct_adapter.hpp index 60fe8c274..0e4f64c1f 100644 --- a/include/boost/iostreams/detail/adapter/direct_adapter.hpp +++ b/include/boost/iostreams/detail/adapter/direct_adapter.hpp @@ -126,7 +126,9 @@ class direct_adapter : private direct_adapter_base { // Direct device access. Direct& operator*() { return d_; } + const Direct& operator*() const { return d_; } Direct* operator->() { return &d_; } + const Direct* operator->() const { return &d_; } #if BOOST_WORKAROUND(BOOST_MSVC, <= 1310) private: template diff --git a/include/boost/iostreams/detail/adapter/filter_adapter.hpp b/include/boost/iostreams/detail/adapter/filter_adapter.hpp index a2ab49250..997f017c1 100644 --- a/include/boost/iostreams/detail/adapter/filter_adapter.hpp +++ b/include/boost/iostreams/detail/adapter/filter_adapter.hpp @@ -34,6 +34,7 @@ class filter_adapter { public: explicit filter_adapter(param_type t) : t_(t) { } T& component() { return t_; } + const T& component() const { return t_; } template void close(Device& dev) diff --git a/include/boost/iostreams/detail/broken_overload_resolution/stream.hpp b/include/boost/iostreams/detail/broken_overload_resolution/stream.hpp index 834f996f4..d7f4d2677 100644 --- a/include/boost/iostreams/detail/broken_overload_resolution/stream.hpp +++ b/include/boost/iostreams/detail/broken_overload_resolution/stream.hpp @@ -107,7 +107,9 @@ struct stream : detail::stream_base { void set_auto_close(bool close) { this->member.set_auto_close(close); } bool strict_sync() { return this->member.strict_sync(); } Device& operator*() { return *this->member; } + const Device& operator*() const { return *this->member; } Device* operator->() { return &*this->member; } + const Device* operator->() const { return &*this->member; } private: template void open_impl(mpl::false_, const U0& u0) diff --git a/include/boost/iostreams/detail/broken_overload_resolution/stream_buffer.hpp b/include/boost/iostreams/detail/broken_overload_resolution/stream_buffer.hpp index d5c710708..899580177 100644 --- a/include/boost/iostreams/detail/broken_overload_resolution/stream_buffer.hpp +++ b/include/boost/iostreams/detail/broken_overload_resolution/stream_buffer.hpp @@ -117,7 +117,9 @@ class stream_buffer } #endif // !BOOST_WORKAROUND(BOOST_MSVC, <= 1300) //---------------------------// T& operator*() { return *this->component(); } + const T& operator*() const { return *this->component(); } T* operator->() { return this->component(); } + const T* operator->() const { return this->component(); } private: template void open_impl(mpl::false_, const U0& u0) diff --git a/include/boost/iostreams/detail/streambuf/direct_streambuf.hpp b/include/boost/iostreams/detail/streambuf/direct_streambuf.hpp index a55c4621e..c7464026a 100644 --- a/include/boost/iostreams/detail/streambuf/direct_streambuf.hpp +++ b/include/boost/iostreams/detail/streambuf/direct_streambuf.hpp @@ -66,6 +66,7 @@ class direct_streambuf // Declared in linked_streambuf. T* component() { return storage_.get(); } + const T* component() const { return storage_.get(); } protected: BOOST_IOSTREAMS_USING_PROTECTED_STREAMBUF_MEMBERS(base_type) direct_streambuf(); diff --git a/include/boost/iostreams/detail/streambuf/indirect_streambuf.hpp b/include/boost/iostreams/detail/streambuf/indirect_streambuf.hpp index 9f159a369..8906e65df 100644 --- a/include/boost/iostreams/detail/streambuf/indirect_streambuf.hpp +++ b/include/boost/iostreams/detail/streambuf/indirect_streambuf.hpp @@ -72,6 +72,7 @@ class indirect_streambuf // Declared in linked_streambuf. T* component() { return &*obj(); } + const T* component() const { return &*obj(); } protected: BOOST_IOSTREAMS_USING_PROTECTED_STREAMBUF_MEMBERS(base_type) @@ -101,6 +102,7 @@ class indirect_streambuf //----------Accessor functions--------------------------------------------// wrapper& obj() { return *storage_; } + const wrapper& obj() const { return *storage_; } streambuf_type* next() const { return next_; } buffer_type& in() { return buffer_.first(); } buffer_type& out() { return buffer_.second(); } diff --git a/include/boost/iostreams/stream.hpp b/include/boost/iostreams/stream.hpp index c581837b7..69eb44269 100644 --- a/include/boost/iostreams/stream.hpp +++ b/include/boost/iostreams/stream.hpp @@ -150,8 +150,11 @@ struct stream : detail::stream_base { void set_auto_close(bool close) { this->member.set_auto_close(close); } bool strict_sync() { return this->member.strict_sync(); } Device& operator*() { return *this->member; } + const Device& operator*() const { return *this->member; } Device* operator->() { return &*this->member; } + const Device* operator->() const { return &*this->member; } Device* component() { return this->member.component(); } + const Device* component() const { return this->member.component(); } private: void open_impl(const Device& dev BOOST_IOSTREAMS_PUSH_PARAMS()) // For forwarding. { diff --git a/include/boost/iostreams/stream_buffer.hpp b/include/boost/iostreams/stream_buffer.hpp index dbcb786c6..e1394aad3 100644 --- a/include/boost/iostreams/stream_buffer.hpp +++ b/include/boost/iostreams/stream_buffer.hpp @@ -95,7 +95,9 @@ class stream_buffer BOOST_IOSTREAMS_PUSH_PARAMS, BOOST_IOSTREAMS_PUSH_ARGS ) T& operator*() { return *this->component(); } + const T& operator*() const { return *this->component(); } T* operator->() { return this->component(); } + const T* operator->() const { return this->component(); } private: void open_impl(const T& t BOOST_IOSTREAMS_PUSH_PARAMS()) { // Used for forwarding.