Sane C++ Libraries
C++ Platform Abstraction Libraries
Loading...
Searching...
No Matches
Language Utilities

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

Classes

struct  SC::StrongID< TagType, IDType, InvalidValue >
 Strongly typed ID (cannot be assigned incorrectly to another ID) More...
 
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::OpaqueObject< Definition >
 Hides implementation details from public headers (static PIMPL). More...
 
struct  SC::TimeMs
 A vocabulary type representing a time interval in milliseconds since epoch. 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::UniqueHandle< Definition >
 Move only handle that has a special tag value flagging its invalid state. More...
 
struct  SC::MaxValue
 An object that can be converted to any primitive type providing its max value. More...
 

Macros

#define SC_TRY(expression)
 Checks the value of the given expression and if failed, returns this value to caller.
 
#define SC_TRY_MSG(expression, failedMessage)
 Checks the value of the given expression and if failed, returns a result with failedMessage to caller.
 

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 )
 
using SC::uint8_t = unsigned char
 Platform independent (1) byte unsigned int.
 
using SC::uint16_t = unsigned short
 Platform independent (2) bytes unsigned int.
 
using SC::uint32_t = unsigned int
 Platform independent (4) bytes unsigned int.
 
using SC::uint64_t = unsigned long long
 Platform independent (8) bytes unsigned int.
 
using SC::int8_t = signed char
 Platform independent (1) byte signed int.
 
using SC::int16_t = short
 Platform independent (2) bytes signed int.
 
using SC::int32_t = int
 Platform independent (4) bytes signed int.
 
using SC::int64_t = long long
 Platform independent (8) bytes signed int.
 
using SC::size_t = unsigned long
 Platform independent unsigned size type.
 
using SC::ssize_t = signed long
 Platform independent signed size type.
 

Functions

template<typename T >
constexpr T && SC::move (T &value)
 Converts an lvalue to an rvalue reference.
 
template<typename T >
constexpr T && SC::forward (typename TypeTraits::RemoveReference< T >::type &value)
 Forwards an lvalue or an rvalue as an rvalue reference.
 
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.
 
template<typename T >
constexpr void SC::swap (T &t1, T &t2)
 Swaps the values of two objects.
 
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.
 
void * operator new (SC::size_t, void *p, SC::PlacementNew) noexcept
 Custom placement new using SC::PlacementNew class.
 
void * operator new[] (SC::size_t, void *p, SC::PlacementNew) noexcept
 

Variables

template<typename FuncType , int LAMBDA_SIZE = sizeof(void*) * 2>
struct SC_COMPILER_EXPORT SC::Function
 Wraps function pointers, member functions and lambdas without ever allocating.
 

Detailed Description

Language Utilities Utility classes allowing common C++ constructs.

Tag structure for custom placement new

Macro Definition Documentation

◆ 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:13

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:25

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 = short

#include <PrimitiveTypes.h>

Platform independent (2) bytes signed int.

◆ int32_t

using SC::int32_t = int

#include <PrimitiveTypes.h>

Platform independent (4) bytes signed int.

◆ int64_t

using SC::int64_t = long long

#include <PrimitiveTypes.h>

Platform independent (8) bytes signed int.

◆ int8_t

using SC::int8_t = signed char

#include <PrimitiveTypes.h>

Platform independent (1) byte signed int.

◆ native_char_t

using SC::native_char_t = 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 = unsigned long

#include <PrimitiveTypes.h>

Platform independent unsigned size type.

◆ ssize_t

using SC::ssize_t = signed long

#include <PrimitiveTypes.h>

Platform independent signed size type.

◆ uint16_t

using SC::uint16_t = unsigned short

#include <PrimitiveTypes.h>

Platform independent (2) bytes unsigned int.

◆ uint32_t

using SC::uint32_t = unsigned int

#include <PrimitiveTypes.h>

Platform independent (4) bytes unsigned int.

◆ uint64_t

using SC::uint64_t = unsigned long long

#include <PrimitiveTypes.h>

Platform independent (8) bytes unsigned int.

◆ uint8_t

using SC::uint8_t = unsigned char

#include <PrimitiveTypes.h>

Platform independent (1) byte unsigned int.

Function Documentation

◆ forward() [1/2]

template<typename T >
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 >
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 >
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 >
void SC::swap ( T & t1,
T & t2 )
inlineconstexpr

#include <Compiler.h>

Swaps the values of two objects.

Variable Documentation

◆ Function

template<typename FuncType , int LAMBDA_SIZE = sizeof(void*) * 2>
struct SC_COMPILER_EXPORT SC::Function

#include <Function.h>

Wraps function pointers, member functions and lambdas without ever allocating.


Template Parameters
FuncTypeType of function to be wrapped (Lambda, free function or pointer to member function)
Note
Size of lambdas or less than LAMBDA_SIZE (currently 2 * sizeof(void*)).
If lambda is bigger than LAMBDA_SIZE the constructor will static assert.

Example:

// A regular class with a member function
struct SomeClass
{
float memberValue = 2.0;
int memberFunc(float a) { return static_cast<int>(a + memberValue); }
};
// A Functor with operator ()
struct SomeFunctor
{
float memberValue = 2.0;
int operator()(float a) { return static_cast<int>(a + memberValue); }
};
// Free function
int someFunc(float a) { return static_cast<int>(a * 2); }
// Class too big to be grabbed by copy
struct BigClass
{
SC::uint64_t values[4];
};
void SC::FunctionTest::functionDocumentationSnippet()
{
SomeClass someClass;
Function<int(float)> func;
func = &someFunc; // Bind free func
func.bind<SomeClass, &SomeClass::memberFunc>(someClass); // Bind member func
func = [](float a) -> int { return static_cast<int>(a + 1.5); }; // Bind lambda func
func = SomeFunctor{2.5}; // Bind a functor
// If you feel brave enough you can retrieve the bound functor by knowing its type
SC_ASSERT_RELEASE(func.dynamicCastTo<SomeFunctor>()->memberValue == 2.5f);
// This will static_assert because sizeof(BigClass) is bigger than LAMBDA_SIZE
// BigClass bigClass;
// func = [bigClass](float a) -> int { return static_cast<int>(a);};
}