Any C++20 features you would like to use?

Ilmari Lauhakangas ilmari.lauhakangas at libreoffice.org
Sun Jun 19 05:01:08 UTC 2022


We recently branched, so it's a good time to think about compiler baselines.

Currently our Windows and macOS baselines are leading the pack in terms 
of latest C++ features. Our Linux distro baseline with RHEL/CentOS 7 
provides relatively fresh GCC and Clang versions through extra repositories.

GCC 11 in SCL:
https://centos.pkgs.org/7/centos-sclo-rh-x86_64/devtoolset-11-gcc-11.2.1-1.2.el7.x86_64.rpm.html

llvm 13 in EPEL 7:
https://centos.pkgs.org/7/epel-x86_64/llvm13-13.0.1-1.el7.x86_64.rpm.html

In the future, probably the biggest pressure for bumpage will be on 
Clang as it is lagging behind the competition in features.

I'm not advocating for any particular bump target, but it would be 
interesting to hear if people have any wishes regarding C++20 features. 
What has so far come up:

- template-parameter-list for generic lambdas 
https://en.cppreference.com/w/cpp/language/lambda#Syntax (available by 
bumping GCC to 8 and Clang to 9)
- std::endian https://en.cppreference.com/w/cpp/types/endian (available 
by bumping GCC to 8)

I got the idea to look at what Boost library features we use and what 
could be replaced by standard features. I don't mean we should aim for 
some wholesale banishment of Boost, but for sure minimising its use has 
various benefits like reduced build times. Cleaner code, easier 
usability and better performance are good reasons to stick with Boost libs.

Command used to discover Boost stuff:
git grep -Eho 'boost::[a-z_:]+' | sort | uniq

Irrelevant stuff like patches in external/boost ignored.

Boost libraries we might want to replace:

- boost::bind http://www.boost.org/libs/bind 
https://en.cppreference.com/w/cpp/utility/functional/bind Already in 
C++11. Has some subtle differences to std::bind, but is only used in 
sdext/source/pdfimport/pdfparse/pdfparse.cxx
- boost::enable_shared_ptr_from_this Only mentioned in obsolete comments 
in slideshow/source/inc/soundplayer.hxx
- boost::filesystem https://www.boost.org/libs/filesystem/doc/index.htm 
https://en.cppreference.com/w/cpp/filesystem Would require GCC 8 (after 
bumping macOS runtime to 10.15 in Jan 2023)
- boost::lexical_cast 
https://www.boost.org/doc/html/boost_lexical_cast.html 
https://en.cppreference.com/w/cpp/utility#Elementary_string_conversions 
Would require GCC 8. Full floating-point support not in any Clang 
version yet, but we use Dragonbox for float-to-string anyway
- boost::optional (::make_optional only used in libetonyek) 
https://www.boost.org/libs/optional 
https://en.cppreference.com/w/cpp/utility/optional 
https://www.cppstories.com/2018/05/using-optional/#migration-from-boostoptional 
C++17, no need to bump anything
- boost::shared_ptr (related ::dynamic_pointer_cast) 
https://www.boost.org/libs/smart_ptr 
https://en.cppreference.com/w/cpp/memory/shared_ptr Already in C++11. 
Used mostly because it is used in libcmis
- boost::starts_with 
https://www.boost.org/doc/libs/release/doc/html/boost/algorithm/starts_with.html 
https://en.cppreference.com/w/cpp/string/basic_string/starts_with Would 
require GCC 9. Used in libcmis
- boost::variant https://www.boost.org/libs/variant 
https://en.cppreference.com/w/cpp/utility/variant 
https://www.cppstories.com/2018/06/variant/#migration-from-boostvariant 
C++17, no compiler bump needed. We just bumped our macOS runtime to 
10.14, so all features related to variant are safe to use

Boost libraries we can revisit when C++23 features become available:

- boost::gregorian and boost::posix_time 
https://www.boost.org/libs/date_time 
https://en.cppreference.com/w/cpp/header/chrono std::chrono might have 
enough features starting from C++20. However, a design issue related to 
formatting is only fixed in C++23 (approved): 
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2372r3.html
- Range (::adaptors, ::make_iterator_range) 
https://www.boost.org/libs/range 
https://en.cppreference.com/w/cpp/ranges More fully featured in C++23
- boost::split (used with boost::is_any_of) 
https://www.boost.org/doc/libs/1_79_0/doc/html/boost/algorithm/split.html 
https://en.cppreference.com/w/cpp/ranges/split_view Becomes more robust 
in C++23 (approved): 
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2210r2.html

Boost libraries we probably don't want to replace (happy to be proven 
wrong):

- boost::circular_buffer https://www.boost.org/libs/circular_buffer A 
special container with good performance
- boost::container::flat_map Special container for special purpose
- boost::hash https://www.boost.org/libs/container_hash 
https://en.cppreference.com/w/cpp/utility/hash Maybe used for some good 
reason?
- boost::intrusive::circular_list_algorithms 
https://www.boost.org/libs/intrusive Special container for special 
purpose. Used only in sw/inc/ring.hxx
- boost::intrusive_ptr https://www.boost.org/libs/smart_ptr Special 
pointer with no equivalent in STL
- boost::iterator_facade https://www.boost.org/libs/iterator 
https://vector-of-bool.github.io/2020/06/13/cpp20-iter-facade.html Can 
be done with C++20 in a "suprisingly easy" way, though. Used only in 
sw/inc/ring.hxx
- boost::locale https://www.boost.org/libs/locale It makes std::locale 
pleasant to use
- boost::math::policies, boost::math::sinc_pi 
https://www.boost.org/doc/libs/release/libs/math/doc/html/policy.html 
https://www.boost.org/doc/libs/release/libs/math/doc/html/math_toolkit/sinc/sinc_pi.html 
Special function for computing the Sinus Cardinal of x
- boost::multi_array https://www.boost.org/libs/multi_array Only used in 
vcl/source/window/layout.cxx but maybe for a reason
- boost::multi_index, ::multi_index_container 
https://www.boost.org/libs/multi_index Special container for special purpose
- boost::noinit_adaptor 
https://www.boost.org/doc/libs/release/libs/core/doc/html/core/noinit_adaptor.html 
Special template for allocator conversion
- boost::numeric_cast 
https://www.boost.org/doc/libs/release/libs/numeric/conversion/doc/html/boost_numericconversion/improved_numeric_cast__.html 
Unable to locate standard equivalent
- boost::polymorphic_downcast 
https://www.boost.org/doc/libs/release/doc/html/conversion/polymorphic_casts.html 
Unable to locate standard equivalent
- boost::property_tree https://www.boost.org/libs/property_tree Special 
data structure
- boost::ptr_* https://www.boost.org/libs/ptr_container Semantics are 
different from STL
- boost::rational https://www.boost.org/libs/rational/rational.html 
Unable to locate standard equivalent
- boost::spirit::classic 
https://www.boost.org/doc/libs/release/libs/spirit/classic/index.html No 
parser generators in the standard yet
- boost::trim_copy 
https://www.boost.org/doc/libs/release/doc/html/boost/algorithm/trim_copy.html 
Only used in desktop/source/lib/init.cxx Not very complicated to 
implement, though. We have one for OStrings, comphelper::string::strip
- boost::unordered_* In the upcoming Boost 1.80, unordered containers 
will have better performance than anything in STL: 
https://www.reddit.com/r/cpp/comments/vbdr3z/new_boostunordered_containers_have_big/

Ilmari


More information about the LibreOffice mailing list