Sane C++ Libraries
C++ Platform Abstraction Libraries
Language Utilities

Language Utilities Utility classes allowing common C++ constructs. More...

Classes

struct  SC::AlignedStorage< N, Alignment >
 A buffer of bytes with given alignment. More...
 
struct  SC::Assert
 Functions and macros to assert, exit() or abort() and capture backtraces. More...
 
struct  SC::Deferred< F >
 Executes a function at end of current scope (in the spirit of Zig defer keyword). More...
 
struct  SC::Function< FuncType >
 Wraps function pointers, member functions and lambdas without ever allocating. More...
 
struct  SC::MaxValue
 An object that can be converted to any primitive type providing its max value. More...
 
struct  SC::Memory
 Centralized functions to allocate, reallocate and deallocate memory. More...
 
struct  SC::OpaqueObject< Definition >
 Hides implementation details from public headers (static PIMPL). More...
 
struct  SC::Result
 An ascii string used as boolean result. SC_TRY macro forwards errors to caller. More...
 
struct  SC::Span< Type >
 View over a contiguous sequence of items (pointer + size in elements). More...
 
struct  SC::TaggedType< EnumType, enumValue, MemberType >
 Associate a Type to an Enum, as required by TaggedUnion. More...
 
struct  SC::TaggedUnion< Union >
 Type safe union with an enum type, where each type has an associated enum value. More...
 
struct  SC::UniqueHandle< Definition >
 Move only handle that has a special tag value flagging its invalid state. More...
 

Macros

#define SC_TRY(expression)
 Checks the value of the given expression and if failed, returns this value to caller. More...
 
#define SC_TRY_MSG(expression, failedMessage)
 Checks the value of the given expression and if failed, returns a result with failedMessage to caller. More...
 
#define SC_TRUST_RESULT(expression)   SC_ASSERT_RELEASE(expression)
 Asserts that the given result is valid. More...
 

Typedefs

template<typename T >
using SC::Delegate = Function< void(T)>
 
using SC::Action = Function< void()>
 
using SC::native_char_t = char
 The native char for the platform (wchar_t (4 bytes) on Windows, char (1 byte) everywhere else ) More...
 
using SC::uint8_t = unsigned char
 Platform independent (1) byte unsigned int. More...
 
using SC::uint16_t = unsigned short
 Platform independent (2) bytes unsigned int. More...
 
using SC::uint32_t = unsigned int
 Platform independent (4) bytes unsigned int. More...
 
using SC::uint64_t = unsigned long long
 Platform independent (8) bytes unsigned int. More...
 
using SC::int8_t = signed char
 Platform independent (1) byte signed int. More...
 
using SC::int16_t = short
 Platform independent (2) bytes signed int. More...
 
using SC::int32_t = int
 Platform independent (4) bytes signed int. More...
 
using SC::int64_t = long long
 Platform independent (8) bytes signed int. More...
 
using SC::size_t = unsigned long
 Platform independent unsigned size type. More...
 
using SC::ssize_t = signed long
 Platform independent signed size type. More...
 

Functions

template<typename T >
constexpr T && SC::move (T &value)
 Converts an lvalue to an rvalue reference. More...
 
template<typename T >
constexpr T && SC::forward (typename TypeTraits::RemoveReference< T >::type &value)
 Forwards an lvalue or an rvalue as an rvalue reference. More...
 
template<typename T >
constexpr T && SC::forward (typename TypeTraits::RemoveReference< T >::type &&value)
 Forwards an rvalue as an rvalue reference, with a check that it's not an lvalue reference. More...
 
template<typename T >
constexpr void SC::swap (T &t1, T &t2)
 Swaps the values of two objects. More...
 
template<typename F >
Deferred< F > SC::MakeDeferred (F &&f)
 Creates a Deferred object holding a function that will be invoked at end of current scope. More...
 
void * operator new (SC::size_t, void *p, SC::PlacementNew) noexcept
 Custom placement new using SC::PlacementNew class. More...
 

Detailed Description

Language Utilities Utility classes allowing common C++ constructs.

Tag structure for custom placement new.

Macro Definition Documentation

◆ SC_TRUST_RESULT

#define SC_TRUST_RESULT (   expression)    SC_ASSERT_RELEASE(expression)

#include <Result.h>

Asserts that the given result is valid.

◆ SC_TRY

#define SC_TRY (   expression)

#include <Result.h>

Value:
{ \
if (auto _exprResConv = SC::Result(expression)) \
SC_LANGUAGE_LIKELY \
{ \
(void)0; \
} \
else \
{ \
return _exprResConv; \
} \
}
An ascii string used as boolean result. SC_TRY macro forwards errors to caller.
Definition: Result.h:11

Checks the value of the given expression and if failed, returns this value to caller.

◆ SC_TRY_MSG

#define SC_TRY_MSG (   expression,
  failedMessage 
)

#include <Result.h>

Value:
if (not(expression)) \
SC_LANGUAGE_UNLIKELY \
{ \
return SC::Result::Error(failedMessage); \
}
static constexpr Result Error(const char(&msg)[numChars])
Constructs an Error from a pointer to an ASCII string literal.
Definition: Result.h:23

Checks the value of the given expression and if failed, returns a result with failedMessage to caller.

Typedef Documentation

◆ int16_t

using SC::int16_t = typedef short

#include <PrimitiveTypes.h>

Platform independent (2) bytes signed int.

◆ int32_t

using SC::int32_t = typedef int

#include <PrimitiveTypes.h>

Platform independent (4) bytes signed int.

◆ int64_t

using SC::int64_t = typedef long long

#include <PrimitiveTypes.h>

Platform independent (8) bytes signed int.

◆ int8_t

using SC::int8_t = typedef signed char

#include <PrimitiveTypes.h>

Platform independent (1) byte signed int.

◆ native_char_t

using SC::native_char_t = typedef char

#include <PrimitiveTypes.h>

The native char for the platform (wchar_t (4 bytes) on Windows, char (1 byte) everywhere else )

◆ size_t

using SC::size_t = typedef unsigned long

#include <PrimitiveTypes.h>

Platform independent unsigned size type.

◆ ssize_t

using SC::ssize_t = typedef signed long

#include <PrimitiveTypes.h>

Platform independent signed size type.

◆ uint16_t

using SC::uint16_t = typedef unsigned short

#include <PrimitiveTypes.h>

Platform independent (2) bytes unsigned int.

◆ uint32_t

using SC::uint32_t = typedef unsigned int

#include <PrimitiveTypes.h>

Platform independent (4) bytes unsigned int.

◆ uint64_t

using SC::uint64_t = typedef unsigned long long

#include <PrimitiveTypes.h>

Platform independent (8) bytes unsigned int.

◆ uint8_t

using SC::uint8_t = typedef unsigned char

#include <PrimitiveTypes.h>

Platform independent (1) byte unsigned int.

Function Documentation

◆ forward() [1/2]

template<typename T >
constexpr T && SC::forward ( typename TypeTraits::RemoveReference< T >::type &&  value)
constexpr

#include <Compiler.h>

Forwards an rvalue as an rvalue reference, with a check that it's not an lvalue reference.

◆ forward() [2/2]

template<typename T >
constexpr T && SC::forward ( typename TypeTraits::RemoveReference< T >::type &  value)
constexpr

#include <Compiler.h>

Forwards an lvalue or an rvalue as an rvalue reference.

◆ MakeDeferred()

template<typename F >
Deferred< F > SC::MakeDeferred ( F &&  f)

#include <Deferred.h>

Creates a Deferred object holding a function that will be invoked at end of current scope.

Parameters
fThe lambda to be invoked at end of current scope

◆ move()

template<typename T >
constexpr T && SC::move ( T &  value)
constexpr

#include <Compiler.h>

Converts an lvalue to an rvalue reference.

◆ operator new()

void * operator new ( SC::size_t  ,
void *  p,
SC::PlacementNew   
)
inlinenoexcept

#include <PrimitiveTypes.h>

Custom placement new using SC::PlacementNew class.

◆ swap()

template<typename T >
constexpr void SC::swap ( T &  t1,
T &  t2 
)
inlineconstexpr

#include <Compiler.h>

Swaps the values of two objects.