Namespaces | |
namespace | Private_ |
Classes | |
struct | Case |
struct | ComparisonRelationDeclaration |
struct | ComparisonRelationDeclarationBase |
struct | ConvertibleFrom |
struct | ConvertibleTo |
struct | CountedValue |
struct | DefaultNames |
struct | Empty |
class | EmptyObjectForSideEffects |
struct | EqualsComparerAdapter |
Use this to wrap any basic comparer, and produce an Equals comparer. More... | |
class | ExtendableProperty |
ExtendableProperty is a Property which has callbacks associated with it, to be notified when it is accessed or updated. More... | |
struct | FunctionTraits |
Extract the number of arguments, return type, and each individual argument type from a lambda or simple function object. More... | |
struct | GUID |
struct | Identity |
function object whose action is to map its argument, back to the same value it started with (identity function). More... | |
struct | InOrderComparerAdapter |
Use this to wrap any basic comparer, and produce a Less comparer. More... | |
struct | KeyValuePair |
struct | LazyType |
struct | OptionalThreeWayComparer |
ThreeWayComparer for optional types, like builtin one, except this lets you pass in explicit 'T' comparer for the T in optional<T> More... | |
class | Property |
class | ReadOnlyProperty |
class | ScopedUseLocale |
struct | substitution_failure |
struct | substitution_succeeded |
struct | ThreeWayComparerAdapter |
Use this to wrap a basic (ITotallyOrderingComparer) comparer, and produce a Three-Way comparer. More... | |
struct | Version |
class | WriteOnlyProperty |
Concepts | |
concept | IPotentiallyComparer |
concept | IComparer |
concept | IEqualsComparer |
concept | IInOrderComparer |
concept | IThreeWayComparer |
concept | ITotallyOrderingComparer |
concept | IBuiltinArithmetic |
concept true if integral or floatpoint type 'T'. Not sure why not provided by std c++ | |
concept | INoThrowInvocable |
like std::invocable concept, except also requires the invocation doesn't raise exceptions | |
concept | IAnyOf |
concept - trivial shorthand for variadic same_as A or same_as B, or ... | |
concept | trivially_copyable |
concept version of std::is_trivially_copyable_v | |
concept | Boolean_testable |
handy re-usable concept, with the obvious meaning, and strangely omitted from std-c++ (though used in exposition). | |
concept | Weak_Equality_Comparable_With |
equality_comparable_with, but less strict - just checks if it can be equality compared! | |
concept | explicitly_convertible_to |
like convertible_to, but also handling cases where T has an explict CTOR taking From | |
concept | IPair |
return true iff argument type T, is std::pair<a,b> for some a/b types | |
concept | ISharedPtr |
return true iff argument type T, is std::shared_ptr<A> for some A types | |
concept | ITuple |
Concept ITuple<T> check if T is a tuple. | |
concept | IVariant |
| |
concept | IHasSizeMethod |
Concept checks if the given type T has a const size() method which can be called to return a size_t. | |
concept | IEqualToOptimizable |
concept | IHasValueType |
Concept checks if the given type T has a value_type (type) member. | |
concept | IBoundedEnum |
Typedefs | |
template<typename... > | |
using | True = true_type |
template<typename T > | |
using | ExtractValueType_t = typename Private_::ExtractValueType< remove_cvref_t< T > >::type |
Extract the type of elements in a container, or returned by an iterator (value_type) or void it there is no value_type. | |
template<typename T > | |
using | DifferenceType = typename conditional_t< is_enum_v< T >, LazyType< underlying_type_t, T >, LazyType< Private_::BaseDifferenceType_, T > >::type |
template<typename T > | |
using | UnsignedOfIf = typename conditional_t< is_integral_v< T >, LazyType< make_unsigned_t, T >, conditional< true, T, T > >::type |
template<size_t N, class Type > | |
using | RepeatedTuple_t = typename Private_::my_tuple< N, Type >::type |
same_as<RepeatedTuple_t<3,int>,tuple<int,int,int>> | |
template<typename T , typename CHECK_T = remove_cvref_t<T>> | |
using | ArgByValueType = conditional_t<(sizeof(CHECK_T)<=2 *sizeof(void *)) and is_trivially_copyable_v< CHECK_T >, CHECK_T, const CHECK_T & > |
This is an alias for 'T' - but how we want to pass it on stack as formal parameter. | |
Enumerations | |
enum class | ComparisonRelationType { } |
enum class | Endian |
in principle complicated question of correspondence between bit and byte and word numbering, but often fairly simple - similar to but subtler version of std::endian More... | |
Functions | |
template<typename FUNCTOR > | |
constexpr Common::ComparisonRelationDeclaration< ComparisonRelationType::eEquals, remove_cvref_t< FUNCTOR > > | DeclareEqualsComparer (FUNCTOR &&f) |
DeclareEqualsComparer () marks a FUNCTOR (lambda or not) as being a FUNCTOR which compares for equality. | |
template<typename FUNCTOR > | |
constexpr Common::ComparisonRelationDeclaration< ComparisonRelationType::eStrictInOrder, remove_cvref_t< FUNCTOR > > | DeclareInOrderComparer (FUNCTOR &&f) |
DeclareInOrderComparer () marks a FUNCTOR (lambda or not) as being a FUNCTOR which compares for in-order. | |
template<typename FROM_INT_TYPE > | |
constexpr strong_ordering | CompareResultNormalizer (FROM_INT_TYPE f) |
constexpr strong_ordering | ReverseCompareOrder (strong_ordering so) |
constexpr Endian | GetEndianness () |
returns native (std::endian::native) Endianness flag. Can be complicated (mixed, etc). But often very simple (e.g. Endian::eLittle) and for the simple cases, based on std::endian::native. | |
template<integral T> | |
constexpr T | EndianConverter (T value, Endian from, Endian to) |
template<typename ENUM > | |
constexpr ENUM | Inc (ENUM e) |
Increment the given enumeration safely, without a bunch of casts. | |
template<typename ENUM > | |
constexpr underlying_type_t< ENUM > | ToInt (ENUM e) |
Cast the given enum to an int (like static_cast<int>()) - but check range. | |
template<typename ENUM > | |
constexpr make_unsigned_t< underlying_type_t< ENUM > > | GetDistanceSpanned (ENUM e) |
return the distance spanned by an enum, e.g. for use in an array | |
template<typename ENUM > | |
constexpr ENUM | ToEnum (underlying_type_t< ENUM > e) |
Cast the given int to the given ENUM type - (like static_cast<int>()) - but check range. | |
template<typename ENUM > | |
constexpr make_unsigned_t< underlying_type_t< ENUM > > | OffsetFromStart (ENUM e) |
offset of given enum from ENUM::eSTART | |
locale | GetPlatformDefaultLocale () |
void | UsePlatformDefaultLocaleAsDefaultLocale () |
Set the operating system locale into the current C++ locale used by locale functions (and most locale-dependent stroika functions). | |
vector< Characters::String > | GetAvailableLocales () |
List all installed locale names (names which can be passed to std::locale::CTOR) | |
Characters::String | FindLocaleName (const Characters::String &iso2LetterLanguageCode, const Characters::String &iso2LetterTerritoryCode) |
Not all systems appear to follow the same naming conventions for locales, so help lookup. | |
optional< Characters::String > | FindLocaleNameQuietly (const Characters::String &iso2LetterLanguageCode, const Characters::String &iso2LetterTerritoryCode) |
Not all systems appear to follow the same naming conventions for locales, so help lookup. | |
locale | FindNamedLocale (const Characters::String &iso2LetterLanguageCode, const Characters::String &iso2LetterTerritoryCode) |
Find the locale matching these properties (for exception trying) | |
SystemConfiguration | GetSystemConfiguration () |
Get the System Configuration object - note not a system global - because the configuration can change while the app is running. | |
SystemConfiguration::OperatingSystem | GetSystemConfiguration_ActualOperatingSystem () |
SystemConfiguration::OperatingSystem | GetSystemConfiguration_ApparentOperatingSystem () |
unsigned int | GetNumberOfLogicalCPUCores (const chrono::duration< double > &allowedStaleness=1min) |
return the number of currently available CPU cores on this (virtual) machine | |
template<typename T , typename... ARGS> | |
T & | Immortalize (ARGS... args) |
Variables | |
template<typename ARG_T , IComparer< ARG_T > COMPARE_FUNCTION> | |
static constexpr ComparisonRelationType | ExtractComparisonTraits_v |
ExtractComparisonTraits_v<> extracts the @ComparisonRelationType for the given argument comparer. | |
template<template< typename... > typename Detector, typename T , typename SFINAE = void> | |
constexpr bool | is_detected_v = false |
TODO:
TODO:
Notes: I've long thought about doing something like this, but only recently got frustrated with the ugliness of tons of getters and setters. So I googled for solutions, and was surprised there was so little traction behind adding this feature to C++ (from C#).
These links give a few hints about discussions of adding this feature to c++:
TODO:
using Stroika::Foundation::Common::True = typedef true_type |
A template which ignores its template arguments, and always returns true_type; NOT crazy - helpful is template metaprogramming.
Definition at line 188 of file Concepts.h.
using Stroika::Foundation::Common::ExtractValueType_t = typedef typename Private_::ExtractValueType<remove_cvref_t<T> >::type |
Extract the type of elements in a container, or returned by an iterator (value_type) or void it there is no value_type.
If the given T has a field value_type, return it; returns void if T has no value_type
NOTE - similar to std::ranges::range_value_t or std::iter_value_t except works with other types.
Definition at line 445 of file Concepts.h.
using Stroika::Foundation::Common::DifferenceType = typedef typename conditional_t<is_enum_v<T>, LazyType<underlying_type_t, T>, LazyType<Private_::BaseDifferenceType_, T> >::type |
Computes the difference between two types, plus for enums, returns the difference between the underlying types.
Definition at line 72 of file TemplateUtilities.h.
using Stroika::Foundation::Common::UnsignedOfIf = typedef typename conditional_t<is_integral_v<T>, LazyType<make_unsigned_t, T>, conditional<true, T, T> >::type |
Given a type, if there is an unsigned variant of it, convert to that. Works for any type T (and returns T)
Definition at line 86 of file TemplateUtilities.h.
using Stroika::Foundation::Common::ArgByValueType = typedef conditional_t<(sizeof (CHECK_T) <= 2 * sizeof (void*)) and is_trivially_copyable_v<CHECK_T>, CHECK_T, const CHECK_T&> |
This is an alias for 'T' - but how we want to pass it on stack as formal parameter.
This is NOT intended to be used very widely, but can be used to decide systematically (by type) if you should pass a given argument by value or by const reference.
Definition at line 32 of file TypeHints.h.
|
strong |
Comparison logic:
Our comparisons ALL require Comparability; and all the <,<=,>,>= comparisons require Transitivity
Types of Comparers: <, <=, ==, etc, are functions from SxS => bool. They are also called relations (where the relationship need not be comparable). But in our domain, they are all comparable, so all comparers are function<bool(T,T)> - at least logically.
Most of Stroika's containers concern themselves with == testing. The value of == can always be derived from !=, <=, <, >, >=, though not necessarily very efficiently (the greater/less than ones translate one call to two).
A frequently more efficient strategy is compare(T,T)-> int (<0 is <, ==0, means equals, >0 means >). This strategy was widely used in the "C" world (e.g. strcmp, quicksort, etc).
It also appears to be making a comeback for C++20 (http://open-std.org/JTC1/SC22/WG21/docs/papers/2017/p0515r0.pdf)
std-c++ favors a handful of these predefined functions > less > equal_to (to a lesser degree) but also provides > greater > less_equal > greater_equal > not_equal_to
c++ also appears to support this three-way-compare approach rarely (eg. string<>::compare).
The biggest problem with how std-c++ supports these comparison operators, is that typeid(equal_to<int>) is essentially unrelated to typeid(equal_to<char>). There is no 'tag' (as with bidirectional iterators etc) to identify different classes of comparison and so no easy to to leverage the natural relationships between equal_to and less_equal.
THIS is what drives how we do containers/related algorithms (less is equiv to greater for most of them)
Enumerator | |
---|---|
eStrictInOrder | e.g. less<T>, or greater<T> From http://mathworld.wolfram.com/StrictOrder.html A relation < is a strict order on a set S if it is
|
eInOrderOrEquals | <=, or >=, e.g. less_equal<T>, or greater_equal<T>
|
eThreeWayCompare | e.g. function<int(T,T)> - where < 0 return is 'in order' (eStrictInOrder), 0 means equal, and > 0 means reversed order |
|
strong |
in principle complicated question of correspondence between bit and byte and word numbering, but often fairly simple - similar to but subtler version of std::endian
|
constexpr |
DeclareEqualsComparer () marks a FUNCTOR (lambda or not) as being a FUNCTOR which compares for equality.
DeclareEqualsComparer is a trivial wrapper on ComparisonRelationDeclaration, but takes advantage of the fact that you can deduce types on functions arguments not not on type of object for constructor (at least as of C++17).
Definition at line 31 of file Compare.inl.
|
constexpr |
DeclareInOrderComparer () marks a FUNCTOR (lambda or not) as being a FUNCTOR which compares for in-order.
DeclareInOrderComparer is a trivial wrapper on ComparisonRelationDeclaration, but takes advantage of the fact that you can deduce types on functions arguments not not on type of object for constructor (at least as of C++17).
Definition at line 44 of file Compare.inl.
|
constexpr |
Take the given value and map it to -1, 0, 1 - without any compiler warnings. Handy for 32/64 bit etc coding when you maybe comparing different sized values and just returning an int, but don't want the warnings about overflow etc.
Definition at line 226 of file Compare.inl.
|
constexpr |
Map equals to equals, but less becomes greater and greater becomes less
Definition at line 242 of file Compare.inl.
|
constexpr |
returns native (std::endian::native) Endianness flag. Can be complicated (mixed, etc). But often very simple (e.g. Endian::eLittle) and for the simple cases, based on std::endian::native.
if (endian::native == endian::little) { return Endian::eLittle; } else if (endian::native == endian::big) { return Endian::eBig; } else complicated...
Definition at line 25 of file Endian.inl.
|
constexpr |
Utility to convert endianness. Logically this can be defined on any numeric integer type, but for now is restricted to uint16_t, uint32_t;
Its common, for example in networking, when you know the endianness of a source, or target data structure, and you can find YOUR machines endianness via GetEndianness (), this lets you automate the mapping (portably).
Definition at line 60 of file Endian.inl.
|
constexpr |
Increment the given enumeration safely, without a bunch of casts.
\pre ENUM uses Stroika_Define_Enum_Bounds() to define eSTART, eEND \pre e >= typename ENUM::eSTART and e < typename ENUM::eEND
Definition at line 17 of file Enumeration.inl.
|
constexpr |
Cast the given enum to an int (like static_cast<int>()) - but check range.
\pre ENUM uses Stroika_Define_Enum_Bounds() to define eSTART, eEND \pre e >= typename ENUM::eSTART and e < typename ENUM::eEND
This function is handy since class enum's cannot be automatically promoted to integers.
Definition at line 28 of file Enumeration.inl.
|
constexpr |
return the distance spanned by an enum, e.g. for use in an array
|
constexpr |
Cast the given int to the given ENUM type - (like static_cast<int>()) - but check range.
\pre ENUM uses Stroika_Define_Enum_Bounds() to define eSTART, eEND \pre e >= typename ENUM::eSTART and e < typename ENUM::eEND
This function is handy since class enum's cannot be automatically promoted to integers.
Definition at line 52 of file Enumeration.inl.
|
constexpr |
offset of given enum from ENUM::eSTART
\pre ENUM uses Stroika_Define_Enum_Bounds() to define eSTART, eEND \pre e >= typename ENUM::eSTART and e < typename ENUM::eEND
Definition at line 65 of file Enumeration.inl.
std::locale Stroika::Foundation::Common::GetPlatformDefaultLocale | ( | ) |
In C++, the default locale is "C" (aka locale::classic ()), not the one inherited from the OS.
Its not hard to get/set the one from the OS, but I've found it not well documented, so this is intended to make it a little easier/more readable.
Definition at line 13 of file Locale.inl.
void Stroika::Foundation::Common::UsePlatformDefaultLocaleAsDefaultLocale | ( | ) |
Set the operating system locale into the current C++ locale used by locale functions (and most locale-dependent stroika functions).
In C++, the default locale is "C", not the one inherited from the OS. Its not hard to get/set the one from the OS, but I've found it not well documented, so this is intended to make it a little easier/more readable.
Definition at line 38 of file Locale.cpp.
vector< Characters::String > Stroika::Foundation::Common::GetAvailableLocales | ( | ) |
List all installed locale names (names which can be passed to std::locale::CTOR)
I'm quite surprised this appears so hard to to in stdC++. I must be missing something...
Definition at line 65 of file Locale.cpp.
Characters::String Stroika::Foundation::Common::FindLocaleName | ( | const Characters::String & | iso2LetterLanguageCode, |
const Characters::String & | iso2LetterTerritoryCode | ||
) |
Not all systems appear to follow the same naming conventions for locales, so help lookup.
Not all systems appear to follow the same naming conventions for locales, so provide a handy lookup function.
This will throw an exception if no matching locale is found
Definition at line 80 of file Locale.cpp.
optional< Characters::String > Stroika::Foundation::Common::FindLocaleNameQuietly | ( | const Characters::String & | iso2LetterLanguageCode, |
const Characters::String & | iso2LetterTerritoryCode | ||
) |
Not all systems appear to follow the same naming conventions for locales, so help lookup.
Not all systems appear to follow the same naming conventions for locales, so provide a handy lookup function.
This will return nullopt if no matching locale is found
Definition at line 88 of file Locale.cpp.
locale Stroika::Foundation::Common::FindNamedLocale | ( | const Characters::String & | iso2LetterLanguageCode, |
const Characters::String & | iso2LetterTerritoryCode | ||
) |
Find the locale matching these properties (for exception trying)
This will return a valid locale object with the prescribed properties, or it will raise an exception.
Definition at line 143 of file Locale.cpp.
SystemConfiguration Stroika::Foundation::Common::GetSystemConfiguration | ( | ) |
Get the System Configuration object - note not a system global - because the configuration can change while the app is running.
Definition at line 942 of file SystemConfiguration.cpp.
SystemConfiguration::OperatingSystem Stroika::Foundation::Common::GetSystemConfiguration_ActualOperatingSystem | ( | ) |
Return info about the actual operating system this software is running on (if possible to tell, it could be well hidden)
Often virtualization (things like compatability mode in a manifest, or perhaps docker, or WSL) makes the apprarent operating system different than the one you are actually running on).
Definition at line 550 of file SystemConfiguration.cpp.
SystemConfiguration::OperatingSystem Stroika::Foundation::Common::GetSystemConfiguration_ApparentOperatingSystem | ( | ) |
Return info about the apparent operating system this software is running on.
Often virtualization (things like compatability mode in a manifest, or perhaps docker, or WSL) makes the apprarent operating system different than the one you are actually running on).
Definition at line 806 of file SystemConfiguration.cpp.
unsigned int Stroika::Foundation::Common::GetNumberOfLogicalCPUCores | ( | const chrono::duration< double > & | allowedStaleness = 1min | ) |
return the number of currently available CPU cores on this (virtual) machine
This is very roughly GetSystemConfiguration_CPU ().GetNumberOfLogicalCores () BUT - this CAN CHANGE over time, and this routine tries to provide a QUICK (cheap so not 100% guaranteed right) answer but generally will be quicker than GetSystemConfiguration_CPU ().GetNumberOfLogicalCores (), and provides stronger guaranteeds about accurance than std::thread::hardware_concurrency (https://en.cppreference.com/w/cpp/thread/thread/hardware_concurrency)
Definition at line 910 of file SystemConfiguration.cpp.
T & Stroika::Foundation::Common::Immortalize | ( | ARGS... | args | ) |
Create a singleton of a class initialized once, but whose DTOR is never called.
Based on template <class _Ty> _Ty& _Immortalize() from VS2k19 runtime library....
Definition at line 14 of file TemplateUtilities.inl.
|
staticconstexpr |
ExtractComparisonTraits_v<> extracts the @ComparisonRelationType for the given argument comparer.
For common builtin types this is known with no user effort. For user-defined comparers, this will need to be declared (e.g. via ComparisonRelationDeclarationBase)
This is ONLY defined for builtin c++ comparison objects, though your code can define it however you wish for specific user-defined types using ComparisonRelationDeclarationBase<>.
|
constexpr |
// just needed til we have c++ 20 concepts
Credit to https://stackoverflow.com/users/16746390/kenash0625 For his suggestion in https://stackoverflow.com/questions/70119120/how-to-fix-sfinae-check-for-operator-existing-so-that-it-works-with-stdpair/70122139#70122139 See also Detection Idioms - https://segmentfault.com/a/1190000040852065/en
Definition at line 46 of file ConceptsBase.h.