Skip to content

Basic Concepts

Dimo Markov edited this page May 23, 2024 · 4 revisions

Langulus::CT is a namespace filled with all sorts of Compile-Time tools and ConcepTs. Most of them are very similar to ones already available in std, however CT gives the added benefit of making them all variadic to reduce boilerplate. You no longer have to do std::is_same<T1, T2> && std::is_same<T1, T3>, instead you just write CT::Exact<T1, T2, T3>. Many of the concepts will also ignore references, whenever that makes sense. Langulus::Core in particular serves only a small portion of these concepts. Here's a catalogue:

  • IsConstexpr(Lambda) -> bool - check if a statement encapsulated in a lambda is constexpr. Leverages that lambda expressions can be constexpr as of C++17.
  • Complete<T...> - check if all T are complete (defined), by exploiting sizeof. Usefulness of this is limited to the first instantiation. Any other use is undefined and might produce wrong results on some compilers. Thankfully, most modern compilers do detect if a definition changes inbetween completeness checks, so it is highly unlikely it causes any real harm.
  • Same<T1, TN...> - true if decayed T1 matches all decayed TN types. Ignores density and cv-qualifiers.
  • SameAsOneOf<T1, TN...> - true if decayed T1 matches at least one of the decayed TN types. Ignores density and cv-qualifiers.
  • Similar<T1, TN...> - true if unqualified T1 matches all unqualified TN types. Ignores only cv-qualifiers.
  • SimilarAsOneOf<T1, TN...> - true if unqualified T1 matches at least one of the unqualified TN types. Ignores only cv-qualifiers.
  • Exact<T1, TN...> - true if T1 matches all TN types exactly, including any cv-qualifiers or indirections.
  • ExactAsOneOf<T1, TN...> - true if T1 matches at least one of TN types exactly, including any cv-qualifiers or indirections.
  • Array<T...> - true if all T are bounded array types. References will be ignored. See std::is_bounded_array_v;
  • Function<T...> - true if all T are raw function signatures. See std::is_function_v
  • Sparse<T...> - true if all T are pointers or bounded arrays. References will be ignored.
  • Dense<T...> - true if all T are not pointers, nor bounded arrays. References will be ignored.
  • Reference<T...> - true if all T are references.
  • NotReference<T...> - true if all T are NOT references.
  • Aggregate<T...> - true if all T are aggregate types. References will be ignored.
  • NotAggregate<T...> - true if all T are NOT aggregate types. References will be ignored.
  • Constant<T...> - true if all T are const on the top-most indirection. References will be ignored.
  • Mutable<T...> - true if all T are not const on the top-most indirection. References will be ignored.
  • Volatile<T...> - true if all T have the volatile qualifier. References will be ignored.
  • Convoluted<T...> - true if all T have both the const and the volatile qualifiers. References will be ignored.
  • Fundamental<T...> - true if all T are fundamental types. References will be ignored.
  • Signed<T...> - true if all T are signed numbers. std::is_signed_v is crap, because it assumes that all types are int-initializable. This one is better. Doesn't apply to numbers only, but anything negatable.
  • Unsigned<T...> - true if all T are unsigned numbers.
  • BuiltinBool<T...> - true if all T are bool.
  • BuiltinCharacter<T...> - true if all T are any of the built-in character types: char, char8_t, char16_t, char32_t, wchar_t. Ignores references.
  • BuiltinInteger<T...>, BuiltinSignedInteger<T...>, BuiltinUnsignedInteger<T...> - true if all T are any of the built-in integer types. Doesn't consider bool to be an integer type (unlike ::std::integral). Ignores references.
  • BuiltinReal<T...> - true if all T are any of the built-in floating number types. Ignores references.
  • BuiltinNumber<T...> - true if all T are any of the built-in number types: BuiltinBool, BuiltinCharacter, BuiltinInteger, or BuiltinReal. Ignores references.
  • StringLiteral<T...> - true if all T are string literals - bounded arrays with an extent. Ignores references.
  • StringPointer<T...> - true if all T are string pointers, hopefully null-terminated. This account to all string pointers that do not have extents. Ignores references.
  • String<T...> - true if all T are strings, either StringLiteral or StringPointer. Ignores references.
  • StdContainer<T...> - true if all T are std containers that satisfy the std::range::range concept.
  • StdContiguousContainer<T...> - true if all T are contiguousstd containers that satisfy the std::range::contiguous_range concept.
  • Convertible<FROM, TO...> - true if FROM is convertible to all TO types. Ignores references.
  • Comparable<LHS, RHS...> - true if LHS is equality-comparable (==) to all RHS types.
  • Sortable<LHS, RHS...> - true if LHS is lesser/greater-comparable (< and >) against all RHS types.
  • Enum<T...> - check if all T are enum types. Ignores references.
  • Arithmetic<T...> - check if all T are arithmetic types. Ignores references.
  • Referencable<T...> - check if all T implement the reference-counter interface. All must have the Reference(Count) -> Count method.
  • Swappable<T...> and SwappableNoexcept<T...> - check if all T are swappable with themselves.
  • DerivedFrom<T, BASE...> - check if the origin of T inherits all BASE types.
  • Related<T1, TN...> - check if the origin of T1 inherits all TN types, or vice versa.
  • VirtuallyDerivedFrom<T, BSAE...> - check if the origin of T inherits all BASE types virtually.
  • BinaryCompatible<T1, TN...> - check if types are Related and of the same size.
  • Slab<T...> - true if all T aren't pointers, have no extents with [], and aren't references.
  • Decayed<T...> - checks whether all T are fully decayed down to their origin types, with all their references, pointers and extents stripped away.
  • NotDecayed<T...> - checks whether all T are not fully decayed, having a reference, pointer, or extent.
  • Void<T...> and TypeErased<T...> - checks whether all T are void types.
  • Data<T...>, DenseData<T...>, SparseData<T...>, DataReference<T...> - checks whether all T are NOT void types.
  • Void<T...> - checks whether all T are exactly std::nullptr_t.
Clone this wiki locally