cxxomfort
rel.20211024
Simple backports for C++ - https://ryan.gulix.cl/fossil.cgi/cxxomfort/
|
Fixes to features in std
Some features in namespace std
are implemented with issues or in unusable fashion in some compilers, and as such cxxomfort can not reuse the names to provide fixed versions.
To deal with this, namespace cxxomfort::fix
offers a number of alternatives or "forwarders" for the features in namespace std. These names either redirect to the std
one if it's working, or to an implementation in cxxomfort when they are not.
Examples of features here:
s("text")
to construct basic_string
s.sv("text")
to construct basic_string_view
s.to_byte()
- Allows std::byte
construction pre-C++14 where uniform initialization for enum classes without constructors is not available.to_bool()
for smart pointers to check their managed status.to_value()
etc for integral_constant
for versions of C++ where the integral conversion operator is not available.to_errc()
- Allows std::errc
code construction from integers pre-C++14.common_type
- Bypasses incorrect implementation in MSVC 2010 where it misses out variadic support and some specific decay case conventions.errc
- Bypasses incorrect std::errc
definition in MSVC versions due to it being declared there as a namespace.hash
hash<> - An extended, extensible version of std::hash
from <functional>
that forwards to the std one but also can beb specialized for families ot types.randmo()
- Obtains a "random" number the same way as rand
does, except it discards some bias.For a more comprehensive listing of fixes, check the various headers' notes on "<b>Interfaces not in std</b>".
Some of the fixes are detailed below:
The basic_string
interface is a mess (over 100 member functions). Also, the fact that the operations are defined as members means cxxomfort (nor any other library) can't extend or backport members added a posteriori, such as what's done in C++20.
cxxomfort gets around this by defining a number of nonmember accessors for the members in basic_string
and basic_string_view
, analogue to what <iterator>
does in C++17 for containers general. This has the advantage that such interface is extensible.
The accessors are provided in namespace cxxomfort::string
and include but are not limited to:
c_str (basic_string const&)
compare (basic_string const&, basic_string const&)
compare (basic_string_view, basic_string_view)
starts_with (basic_string_view str, basic_string_view prefix)
ends_with (basic_string_view str, basic_string_view suffix)
contains (basic_string_view str, basic_string_view needle)
byte
values. integral_constant
. experimental/lfv2
)