2020-02-12 00:29:35 -08:00
|
|
|
/*
|
|
|
|
Title: C++ Aliasing Library
|
|
|
|
Author: Edward R. Gonzalez
|
|
|
|
Date:
|
|
|
|
|
|
|
|
Description:
|
|
|
|
This is a segment of the C++ Assist Library I use for other code.
|
|
|
|
|
|
|
|
This merely removes the need to use operators I don't like and wraps them in easier to manage typedefs, functions or macros
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2020-02-17 09:39:31 -08:00
|
|
|
#include <algorithm >
|
|
|
|
#include <chrono >
|
|
|
|
#include <cstdarg >
|
|
|
|
#include <cstddef >
|
|
|
|
#include <exception >
|
|
|
|
#include <forward_list>
|
|
|
|
#include <fstream >
|
|
|
|
#include <functional >
|
|
|
|
#include <iostream >
|
|
|
|
#include <cmath >
|
|
|
|
#include <map >
|
|
|
|
#include <memory >
|
|
|
|
#include <queue >
|
|
|
|
#include <sstream >
|
|
|
|
#include <stdexcept >
|
|
|
|
#include <string >
|
|
|
|
#include <vector >
|
|
|
|
#include <thread >
|
|
|
|
#include <tuple >
|
|
|
|
#include <typeindex >
|
|
|
|
#include <utility >
|
2020-02-13 22:13:16 -08:00
|
|
|
|
|
|
|
|
|
|
|
|
2020-02-12 00:29:35 -08:00
|
|
|
// Macros
|
|
|
|
|
|
|
|
#define sfn \
|
|
|
|
auto
|
|
|
|
|
|
|
|
#define deduce \
|
|
|
|
auto
|
|
|
|
|
2020-02-20 22:18:07 -08:00
|
|
|
#define ro \
|
|
|
|
const
|
|
|
|
|
|
|
|
#define Ref(...) \
|
|
|
|
__VA_ARGS__&
|
2020-02-12 00:29:35 -08:00
|
|
|
|
|
|
|
#define rRef(_type) \
|
|
|
|
_type&&
|
|
|
|
|
|
|
|
|
2020-02-15 19:32:26 -08:00
|
|
|
|
2020-02-12 00:29:35 -08:00
|
|
|
// Aliases
|
|
|
|
|
|
|
|
// Fundamental
|
|
|
|
|
|
|
|
using uInt64 = unsigned long long int;
|
|
|
|
|
2020-02-15 19:32:26 -08:00
|
|
|
|
|
|
|
|
2020-02-12 00:29:35 -08:00
|
|
|
// Pointers
|
|
|
|
|
|
|
|
template<typename Type>
|
|
|
|
using ptr = Type*;
|
|
|
|
|
|
|
|
template<typename ReturnType, typename... ParamTypes>
|
|
|
|
using FnPtr = ReturnType(*)(ParamTypes...);
|
|
|
|
|
2020-02-20 22:18:07 -08:00
|
|
|
template<typename Type>
|
|
|
|
using SPtr = std::shared_ptr<Type>;
|
|
|
|
|
|
|
|
template<typename Type>
|
|
|
|
using UPtr = std::unique_ptr<Type>;
|
|
|
|
|
|
|
|
|
|
|
|
// Delegating
|
|
|
|
|
2020-02-14 23:21:27 -08:00
|
|
|
template<typename FnType>
|
|
|
|
using Delegate = std::function<FnType>;
|
|
|
|
|
|
|
|
template<typename ReturnType, typename... ParamTypes>
|
|
|
|
using Func = ReturnType(ParamTypes...);
|
|
|
|
|
2020-02-15 19:32:26 -08:00
|
|
|
|
|
|
|
|
2020-02-12 00:29:35 -08:00
|
|
|
// Strings
|
|
|
|
|
|
|
|
template<typename CharType>
|
|
|
|
using RawString = ptr<CharType>;
|
|
|
|
|
|
|
|
|
2020-02-15 19:32:26 -08:00
|
|
|
using std::cout;
|
|
|
|
using std::endl;
|
|
|
|
|
2020-02-20 22:18:07 -08:00
|
|
|
using std::ifstream ;
|
|
|
|
using std::ios ;
|
|
|
|
using std::string ;
|
|
|
|
using std::stringstream;
|
|
|
|
|
|
|
|
using DataSize = std::size_t;
|
|
|
|
using Thread = std::thread;
|
2020-02-15 19:32:26 -08:00
|
|
|
|
|
|
|
template<typename... ObjectTypes>
|
|
|
|
using Tuple = std::tuple<ObjectTypes...>;
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-02-12 00:29:35 -08:00
|
|
|
// Enum
|
|
|
|
|
|
|
|
enum class ExitCode
|
|
|
|
{
|
|
|
|
Success = EXIT_SUCCESS,
|
|
|
|
Failed = EXIT_FAILURE
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-02-15 19:32:26 -08:00
|
|
|
|
2020-02-12 00:29:35 -08:00
|
|
|
// Functions
|
|
|
|
|
|
|
|
// Ptr
|
|
|
|
|
|
|
|
template<typename Type>
|
|
|
|
sfn Address(Ref(Type) _instance) -> ptr<Type>
|
|
|
|
{
|
|
|
|
return &_instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Type>
|
2020-02-20 22:18:07 -08:00
|
|
|
sfn Dref(ro ptr<Type> _type) -> Ref(Type)
|
2020-02-12 00:29:35 -08:00
|
|
|
{
|
|
|
|
return *_type;
|
|
|
|
}
|
|
|
|
|
2020-02-15 19:32:26 -08:00
|
|
|
template<typename Type, typename... ParamTypes>
|
|
|
|
sfn MakeUPtr(rRef(ParamTypes)... _params) -> UPtr<Type>
|
|
|
|
{
|
|
|
|
return std::make_unique<Type>(_params...);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Type, typename... ParamTypes>
|
|
|
|
sfn MakeSPtr(rRef(ParamTypes)... _params) -> SPtr<Type>
|
|
|
|
{
|
|
|
|
return std::make_shared<Type>(_params...);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-02-12 00:29:35 -08:00
|
|
|
|
|
|
|
// Exit
|
|
|
|
|
2020-02-20 22:18:07 -08:00
|
|
|
sfn Exit(ro ExitCode _code)
|
2020-02-12 00:29:35 -08:00
|
|
|
{
|
|
|
|
exit(int(_code));
|
|
|
|
}
|
2020-02-13 22:13:16 -08:00
|
|
|
|
|
|
|
// Error Stuff
|
|
|
|
|
2020-02-20 22:18:07 -08:00
|
|
|
sfn ErrorRuntime(ro Ref(std::runtime_error) _error)
|
2020-02-13 22:13:16 -08:00
|
|
|
{
|
|
|
|
std::cout << "Runtime error occurred: " << _error.what() << std::endl;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2020-02-16 22:28:24 -08:00
|
|
|
|