18 #include <string_view>
33 #define GEMPYREUTILSDEBUG(x) GempyreUtils::log(Utils::LogLevel::Debug, x, __FILE__, __LINE__)
36 #define gempyre_utils_assert(b) (b || GempyreUtils::do_fatal("Panic!", nullptr, __FILE__, __LINE__))
38 #define gempyre_utils_assert_x(b, x) (b || GempyreUtils::do_fatal(x, nullptr, __FILE__, __LINE__))
40 #define gempyre_utils_assert_x_f(b, x, f) (b || GempyreUtils::do_fatal(x, f, __FILE__, __LINE__))
42 #define gempyre_utils_fatal(x) GempyreUtils::do_fatal(x, nullptr, __FILE__, __LINE__)
44 #define gempyre_utils_fatal_f(x, f) GempyreUtils::do_fatal(x, f, __FILE__, __LINE__)
46 #define gempyre_utils_auto_clean(p, f) std::unique_ptr<std::remove_pointer<decltype(p)>::type, decltype(&f)> _ ## p (p, &f)
48 #define gempyre_utils_auto_close(p, f) GempyreUtils::_Close<std::decay_t<decltype(p)>, decltype(&f)> _ ## p (p, &f)
53 #define UTILS_EX __declspec(dllexport)
59 using SSIZE_T =
long long;
61 using SSIZE_T = ssize_t;
67 namespace GempyreUtils {
99 virtual bool do_write(
const char* buffer,
size_t count) = 0;
107 class UTILS_EX FileLogWriter :
public LogWriter {
109 FileLogWriter(std::string_view path);
111 bool do_write(
const char* buffer,
size_t count)
override;
113 std::ofstream m_file;
116 class UTILS_EX StreamLogWriter :
public LogWriter {
118 StreamLogWriter(std::ostream& os);
120 bool do_write(
const char* buffer,
size_t count)
override;
140 UTILS_EX std::ostream log_stream(
LogLevel logLevel);
142 template <
typename T,
typename ...Args>
143 inline void log_line(
LogLevel level, std::ostream& os,
const T& e, Args... args) {
145 log_line(level, os, args...);
149 UTILS_EX
void process_exit(
int);
152 inline void log_line(LogLevel level, std::ostream& os,
const T& e) {
153 os << e << std::endl;
154 if(level == LogLevel::Fatal) {
164 template <
typename T,
typename ...Args>
167 auto os = log_stream(level);
168 log_line(level, os, e, args...);
173 template <LogLevel level,
typename T,
typename ...Args>
174 inline void write_log(
const T& e, Args... args) {
175 log(level, e, args...);
180 template <
typename T,
typename ...Args>
182 write_log<LogLevel::Debug, T, Args...>(e, args...);
187 inline bool do_fatal(std::string_view txt, std::function<
void()> f,
const char* file,
int line) {
189 log(LogLevel::Fatal, txt,
"at", file,
"line:", line);
196 #define __PRETTY_FUNCTION__ __FUNCSIG__
200 #define GEM_DEBUG(...) GempyreUtils::log(GempyreUtils::LogLevel::Debug, __PRETTY_FUNCTION__, __VA_ARGS__)
210 namespace GempyreUtils {
214 template <
typename T,
typename A>
217 _Close(T ref, A&& f) : t(ref), d(f) {}
218 ~_Close() {(void) this->d(this->t);}
219 _Close(_Close&& other) =
default;
220 _Close& operator=(_Close&& other) =
default;
221 _Close(
const _Close& other) =
delete;
222 _Close& operator=(
const _Close& other) =
delete;
231 UTILS_EX
void init();
232 UTILS_EX std::string current_time_string();
233 UTILS_EX std::string last_error();
239 ErrorValue(E&& e) : err{e} {}
240 ErrorValue(
const E& e) : err{e} {}
249 template <
typename E>
struct Error {
256 template <
typename R,
typename E = std::
string>
257 struct Result :
private std::variant<R, Error<E>> {
267 constexpr
Result(R&& r) : std::variant<R, Err>{r} {}
270 constexpr
Result(Err&& e) : std::variant<R, Err>{e} {}
273 constexpr
Result(
const R& r) : std::variant<R, Err>{r} {}
276 constexpr
Result(
const Err& e) : std::variant<R,Err>{e} {}
294 constexpr
operator bool()
const {
return std::get_if<R>(
this);}
296 constexpr
operator std::optional<R>()
const {
return has_value() ? std::make_optional<R>(
value()) : std::nullopt;}
298 constexpr
bool has_value()
const {
return operator bool();}
300 constexpr
const R&
value()
const {
return std::get<R>(*
this);}
302 constexpr
const E&
error()
const {
return std::get<Err>(*this).error;}
304 constexpr R&
value() {
return std::get<R>(*
this);}
308 constexpr
const R&
operator *()
const {
return std::get<R>(*
this);}
312 constexpr
const R*
operator ->()
const {
return &std::get<R>(*
this);}
330 template <
typename R,
typename E>
333 template <
typename R,
typename E>
344 template<
typename T,
typename... A>
346 std::stringstream str;
358 UTILS_EX std::string
qq(std::string_view s);
363 UTILS_EX std::string
chop(std::string_view s);
369 UTILS_EX std::string
chop(std::string_view s, std::string_view chopped);
376 UTILS_EX std::string
substitute(std::string_view str, std::string_view substring, std::string_view substitution);
384 template <
typename T>
385 T convert(std::string_view source) {
386 std::istringstream ss(std::string{source});
397 std::string_view right(std::string_view str,
size_t p) {
398 return str.substr(str.length() - p);
402 inline std::string convert<std::string>(std::string_view source)
404 return std::string{source};
412 template <
typename T>
413 std::optional<T>
parse(std::string_view source) {
414 std::istringstream ss(std::string{source});
416 static_cast<std::istream&
>(ss) >> v;
417 return !ss.fail() ? std::make_optional(v) : std::nullopt;
426 std::transform(std::begin(str), std::end(str), std::back_inserter(n),
427 [](
auto c){
return std::tolower(c);});
438 std::transform(std::begin(str), std::end(str), std::back_inserter(n),
439 [](
auto c){
return std::toupper(c);});
447 inline std::string_view
ltrim(std::string_view str) {
448 const auto begin = std::find_if(str.begin(), str.end(), [](
auto ch) {
451 return str.substr(
static_cast<std::string_view::size_type
>(
452 std::distance(str.begin(), begin)));
458 inline std::string_view
rtrim(std::string_view str) {
459 const auto end = std::find_if(str.rbegin(), str.rend(), [](
auto ch) {
462 return str.substr(0,
static_cast<std::string_view::size_type
>(
463 std::distance(end, str.rend())));
469 inline std::string_view
trim(std::string_view str) {
478 template<
typename T >
480 std::stringstream stream;
481 stream << std::setfill(
'0') << std::setw(
sizeof(T) * 2)
503 template<
typename C,
typename T>
504 std::optional<T> at(
const C& container, std::string_view s,
unsigned index = 0) {
505 const auto range = container.equal_range(s);
506 const auto it = std::next(range.first, index);
507 return (std::distance(range.first, it) < std::distance(range.first, range.second)) ?
508 std::make_optional(it->second) : std::nullopt;
511 template<
typename C,
typename T>
512 T at_or(
const C& container, std::string_view s,
const T& defaultValue,
unsigned index = 0) {
513 const auto v = at<C, T>(container, s, index);
514 return v.has_value() ? *v : defaultValue;
523 template <
class Container = std::vector<std::
string>>
524 Container
split(std::string_view str,
const char splitChar =
' ') {
526 std::istringstream iss(std::string{str});
527 for(std::string token; iss.good() && std::getline(iss, token, splitChar);) {
528 con.insert(con.end(), convert<typename Container::value_type>(token));
534 template <
typename IT>
535 inline constexpr std::string_view make_string_view(IT begin, IT end)
537 return (begin == end) ? std::string_view{
nullptr} : std::string_view{&*begin, std::distance(begin, end)};
546 template <
class T,
typename K =
typename T::key_type>
547 std::vector<K>
keys(
const T& map) {
548 std::vector<K> ks; ks.resize(map.size());
549 std::transform(map.begin(), map.end(), ks.begin(), [](
const auto& p) {return p.first;});
555 struct DefaultJoiner {
556 auto operator()(
const V& v)
const {
return v;}
561 template <
class IT,
typename In,
typename Out>
562 [[deprecated(
"See join with Callable")]] std::string
join(
const IT& begin,
564 std::string_view joinChar =
"",
565 const std::function<Out (
const In&)>& f = [](
const In& k)->Out{
return k;}) {
567 std::ostringstream iss(s);
569 for(
auto it = begin;;) {
571 if(!(++it != end))
break;
572 if(!joinChar.empty())
579 template <
class T,
typename In,
typename Out>
580 [[deprecated(
"See join with Callable")]] std::string
join(
const T& t,
581 std::string_view joinChar =
"",
582 const std::function<Out (
const In&)>& f = [](
const In& v)->Out{
return v;}) {
583 return join(t.begin(), t.end(), joinChar, f);
586 template <class IT, typename In, typename Out, typename = std::enable_if_t<std::is_pointer<IT>::value>>
587 [[deprecated(
"See join with Callable")]] std::string
join(
const IT begin,
589 std::string_view joinChar =
"",
590 const std::function<Out (
const In&)>& f = [](
const In& k)->Out{
return k;}) {
592 std::ostringstream iss(s);
594 for(
auto it = begin;;) {
596 if(!(++it != end))
break;
597 if(!joinChar.empty())
614 template <
typename IT,
typename Callable = DefaultJoiner<
typename IT::value_type>,
615 typename = std::enable_if_t<!std::is_po
inter<IT>::value>>
616 std::string
join(
const IT& begin,
618 std::string_view joinChar =
"",
619 const Callable& f = Callable{}) {
621 std::ostringstream iss(s);
623 for(
auto it = begin;;) {
625 if(!(++it != end))
break;
626 if(!joinChar.empty())
642 typename = std::enable_if_t<std::is_pointer<IT>::value>>
643 std::string
join(
const IT begin,
645 std::string_view joinChar =
"",
646 const Callable& f = Callable{}) {
648 std::ostringstream iss(s);
650 for(
auto it = begin;;) {
652 if(!(++it != end))
break;
653 if(!joinChar.empty())
667 template <
typename T,
typename Callable = DefaultJoiner<
typename T::value_type>>
669 std::string_view joinChar =
"",
670 const Callable& f = Callable{}) {
671 return join(std::begin(t), std::end(t), joinChar, f);
675 template <
typename T>
676 T merge(
const T& b1,
const T& b2) {
677 T bytes(b1.size() + b2.size());
678 auto begin = bytes.begin();
679 std::copy(b1.begin(), b1.end(), begin);
680 std::advance(begin, std::distance(b1.begin(), b1.end()));
681 std::copy(b2.begin(), b2.end(), begin);
686 template <
typename T,
typename ...Arg>
687 T merge(
const T& b1,
const T& b2, Arg ...args) {
688 T bytes(b1.size() + b2.size());
689 auto begin = bytes.begin();
690 std::copy(b1.begin(), b1.end(), begin);
691 std::advance(begin, std::distance(b1.begin(), b1.end()));
692 std::copy(b2.begin(), b2.end(), begin);
693 return merge(bytes, args...);
698 template <
typename IT> IT
advanced(IT it,
int distance) {
699 std::advance(it, distance);
703 template <
typename K,
typename V >
705 std::optional<V>
get_value(
const std::multimap<K, V>& map,
const K& key,
int index = 0)
707 const auto range = map.equal_range(key);
708 return std::distance(range.first, range.second) > index ?
709 std::make_optional((
advanced(range.first, index))->second) : std::nullopt;
721 UTILS_EX std::shared_ptr<expiror> wait_expire(std::chrono::seconds s,
const std::function<
void ()>& onExpire);
724 ~expiror() {m_f.wait();}
727 expiror(std::future<void>&& f) : m_f(std::move(f)) {}
728 std::future<void> m_f{};
729 friend std::shared_ptr<GempyreUtils::expiror> GempyreUtils::wait_expire(std::chrono::seconds s,
const std::function<
void ()>& onExpire);
738 UTILS_EX std::string
hexify(std::string_view src, std::string_view pat);
743 UTILS_EX std::string
unhexify(std::string_view src);
746 enum class OS {OtherOs, MacOs, WinOs, LinuxOs, AndroidOs, RaspberryOs};
752 UTILS_EX std::string html_file_launch_cmd();
771 UTILS_EX std::string
get_link(std::string_view fname);
773 UTILS_EX
bool is_dir(std::string_view fname);
781 UTILS_EX std::string
abs_path(std::string_view rpath);
787 UTILS_EX std::string
path_pop(std::string_view filename,
int steps = 1,
PathStyle path_style = PathStyle::Native);
789 UTILS_EX std::vector<std::string>
entries(std::string_view dirname);
792 [[deprecated(
"use entries")]]
793 inline std::vector<std::string> directory(std::string_view dirname) {
return entries(dirname);}
800 UTILS_EX std::optional<std::string>
read_process(std::string_view processName,
const std::vector<std::string>& params);
804 UTILS_EX std::tuple<std::string, std::string>
split_name(std::string_view filename,
PathStyle path_style = PathStyle::Native);
810 UTILS_EX std::optional<std::string>
system_env(std::string_view env);
818 UTILS_EX
bool rename(std::string_view of, std::string_view nf);
824 UTILS_EX std::optional<std::string>
which(std::string_view filename);
826 UTILS_EX std::string
push_path(std::string_view path, std::string_view name);
828 template<
class ...NAME>
829 std::string
push_path(std::string_view path, std::string_view name, NAME...names) {
834 UTILS_EX
int execute(std::string_view prog,
const std::vector<std::string_view>& parameters);
837 template<
class ...PARAM>
838 UTILS_EX
int execute(std::string_view prog, PARAM...parameters) {
839 std::vector<std::string_view> parameter_list{parameters...};
840 return execute(prog, parameter_list);
853 std::ofstream out(name, std::ios::out | std::ios::binary);
854 std::ostreambuf_iterator<typename T::value_type> iter(out);
855 std::copy(data.begin(), data.end(), iter);
865 std::vector<T>
slurp(std::string_view file,
const size_t max = std::numeric_limits<size_t>::max()) {
868 std::ifstream stream(std::string{file}, std::ios::in | std::ios::binary | std::ios::ate);
869 if(!stream.is_open()) {
870 log(LogLevel::Error,
"Cannot open file",
qq(file));
873 const auto size = std::min(max,
static_cast<size_t>(stream.tellg()));
877 vec.resize(size /
sizeof (T), 0);
878 stream.seekg(std::ios_base::beg);
879 auto ptr =
reinterpret_cast<char*
>(vec.data());
880 stream.read(ptr,
static_cast<std::streamsize
>(size));
886 UTILS_EX std::string slurp(std::string_view file,
const size_t max = std::numeric_limits<size_t>::max());
913 std::vector<std::any>,
914 std::map<std::string, std::any>,
915 std::unordered_map<std::string, std::any>
944 const std::function<
JsonType (std::string_view, std::string_view)>& f = [](
auto,
auto name) {
945 return (GempyreUtils::parse<int>(name)) ?
973 using Options = std::multimap<std::string, std::string>;
976 using Params = std::tuple<ParamList, Options>;
983 UTILS_EX
Params parse_args(
int argc,
char* argv[],
const std::initializer_list<std::tuple<std::string, char, ArgType>>& args);
991 template <
typename T>
993 const auto it = opts.find(std::string{key});
995 return default_value;
996 const auto parsed = parse<T>(it->second);
997 return parsed ? parsed.value() : default_value;
Parent class for LogWriters.
Definition: gempyre_utils.h:82
virtual bool do_write(const char *buffer, size_t count)=0
Implement write to the medium.
virtual std::string header(LogLevel logLevel)
header of class, called before every line, default just returns a timestamp and loglevel string.
virtual ~LogWriter()
Destructor.
virtual bool has_ansi() const
override to return true if this write supports ANSI colors, default just return false
UTILS_EX Result< std::string > to_json_string(const std::any &any, JsonMode mode=JsonMode::Compact)
Convert any type to json string, if possible.
std::tuple< ParamList, Options > Params
a tuple containing ParamList and Options. Used for parse_params.
Definition: gempyre_utils.h:976
UTILS_EX SSIZE_T file_size(std::string_view filename)
File size.
std::optional< V > get_value(const std::multimap< K, V > &map, const K &key, int index=0)
Get a value from a multimap, especially helper for Parameter Options.
Definition: gempyre_utils.h:705
UTILS_EX std::string chop(std::string_view s)
remove newline from end of string
UTILS_EX std::string get_link(std::string_view fname)
Get symbolic link source.
std::vector< T > slurp(std::string_view file, const size_t max=std::numeric_limits< size_t >::max())
Read a file data in one read.
Definition: gempyre_utils.h:865
std::optional< T > parse(std::string_view source)
parse string to value
Definition: gempyre_utils.h:413
UTILS_EX int levenshtein_distance(std::string_view s1, std::string_view s2)
Get a levenshtein distance of strings.
UTILS_EX std::string qq(std::string_view s)
make quoted
UTILS_EX std::string to_str(LogLevel log_level)
Log Level to string.
UTILS_EX std::optional< std::string > read_process(std::string_view processName, const std::vector< std::string > ¶ms)
Read stdout from the process - wait process to end.
UTILS_EX bool file_exists(std::string_view filename)
Test if file with name exits.
UTILS_EX std::string unhexify(std::string_view src)
un hexify hexified string
UTILS_EX Result< std::any > json_to_any(std::string_view str, MapType map_type=MapType::UnorderedMap)
Concert json string to any type.
UTILS_EX std::string remove_spaces(std::string_view str)
remove
constexpr bool operator!=(const Result< R, E > &a, const Result< R, E > &b)
defined if underlaying types defines required operators
Definition: gempyre_utils.h:334
PathStyle
Definition: gempyre_utils.h:768
UTILS_EX std::string push_path(std::string_view path, std::string_view name)
push name to path
std::string_view rtrim(std::string_view str)
trim from right
Definition: gempyre_utils.h:458
UTILS_EX std::string path_pop(std::string_view filename, int steps=1, PathStyle path_style=PathStyle::Native)
Remove elements from path.
UTILS_EX Result< JsonType > get_json_value(const std::any &any, std::string_view path)
Return a value from path.
UTILS_EX std::string home_dir()
Current source dir.
UTILS_EX LogLevel log_level()
Get current log level.
UTILS_EX std::string root_dir()
Current root dir - 'C:\' or '/'.
std::string write_to_temp(const T &data)
Write data to temp file.
Definition: gempyre_utils.h:851
UTILS_EX std::string temp_name()
Generate unique name (prefer std::filesystem if available)
void log_debug(const T &e, Args... args)
Write a debug log.
Definition: gempyre_utils.h:181
UTILS_EX bool rename(std::string_view of, std::string_view nf)
Rename a file.
AddressType
address type
Definition: gempyre_utils.h:757
std::multimap< std::string, std::string > Options
string - string value pairs of options. Used for parse_params.
Definition: gempyre_utils.h:973
UTILS_EX void remove_file(std::string_view filename)
Delete file.
UTILS_EX ResultTrue remove_json_value(std::any &any, std::string_view path)
UTILS_EX std::string substitute(std::string_view str, std::string_view substring, std::string_view substitution)
replace a substrings from a string
UTILS_EX std::string working_dir()
Current source dir.
UTILS_EX std::string abs_path(std::string_view rpath)
Absolute path.
UTILS_EX OS current_os()
Get.
constexpr bool operator==(const Result< R, E > &a, const Result< R, E > &b)
defined if underlaying types defines required operators
Definition: gempyre_utils.h:331
UTILS_EX bool is_executable(std::string_view filename)
is executable
UTILS_EX std::vector< uint8_t > base64_decode(std::string_view data)
Base64 decode.
void log(LogLevel level, const T &e, Args... args)
Write a log line.
Definition: gempyre_utils.h:165
UTILS_EX Params parse_args(int argc, char *argv[], const std::initializer_list< std::tuple< std::string, char, ArgType >> &args)
parse arguments
UTILS_EX ResultTrue set_json_value(std::any &any, std::string_view path, JsonType &&value)
Modifies a given data.
UTILS_EX bool is_valid_utf8(std::string_view str)
Test if a given string is a valid UTF-8 string.
std::string to_low(const T &str)
make lower case string
Definition: gempyre_utils.h:424
UTILS_EX bool is_dir(std::string_view fname)
Is dir.
UTILS_EX std::optional< std::string > which(std::string_view filename)
Try to find a executable from PATH.
IT advanced(IT it, int distance)
Const version of std::advance.
Definition: gempyre_utils.h:698
UTILS_EX ResultTrue make_json_path(std::any &any, std::string_view path, const std::function< JsonType(std::string_view, std::string_view)> &f=[](auto, auto name) { return(GempyreUtils::parse< int >(name)) ? GempyreUtils::JsonType{std::vector< std::any >{}} :GempyreUtils::JsonType{std::unordered_map< std::string, std::any >{}};})
ensure that json path exits
MapType
Json dictionary conversion.
Definition: gempyre_utils.h:899
std::vector< std::string > ParamList
string vector of parameters. Used for parse_params.
Definition: gempyre_utils.h:970
UTILS_EX std::string base_name(std::string_view filename, PathStyle path_style=PathStyle::Native)
Base name.
Result< T, std::string > make_error(A &&... a)
Definition: gempyre_utils.h:345
std::string to_hex(T ival)
Hex presentation of the value.
Definition: gempyre_utils.h:479
ArgType
Option Argument type for parse_args.
Definition: gempyre_utils.h:963
@ REQ_ARG
Option does not have an argument.
@ OPT_ARG
Option has an argument.
T option_or(const Options &opts, std::string_view key, const T &default_value)
get option as type
Definition: gempyre_utils.h:992
std::string_view trim(std::string_view str)
trim from left and right
Definition: gempyre_utils.h:469
UTILS_EX int execute(std::string_view prog, const std::vector< std::string_view > ¶meters)
Execute a program.
UTILS_EX std::optional< std::string > system_env(std::string_view env)
Read environment value.
UTILS_EX std::vector< std::string > entries(std::string_view dirname)
Directory entries.
std::string join(const IT &begin, const IT &end, std::string_view joinChar="", const Callable &f=Callable{})
Join container values, try 1st if compiler can deduct types.
Definition: gempyre_utils.h:616
JsonMode
How json represented as a string.
Definition: gempyre_utils.h:889
UTILS_EX std::vector< std::string > ip_addresses(unsigned addressType)
Try to resolve own ipaddresses.
UTILS_EX bool is_hidden_entry(std::string_view filename)
Is entry hidden.
std::string_view ltrim(std::string_view str)
trim from left
Definition: gempyre_utils.h:447
OS
OS id.
Definition: gempyre_utils.h:746
UTILS_EX bool is_available(int port)
Check if port is free.
UTILS_EX std::string host_name()
Machine host name.
UTILS_EX std::string base64_encode(const unsigned char *bytes, size_t sz)
Base64 encode.
UTILS_EX std::tuple< std::string, std::string > split_name(std::string_view filename, PathStyle path_style=PathStyle::Native)
Name and extension.
Container split(std::string_view str, const char splitChar=' ')
Split sting to container.
Definition: gempyre_utils.h:524
UTILS_EX void set_log_level(LogLevel level)
Set current log level.
LogLevel
The LogLevel enum.
Definition: gempyre_utils.h:71
@ Warning
Something is wrong, Default.
@ Info
At least developer should be worried.
@ Debug_Trace
What is going on.
@ Fatal
All logs disabled.
@ Debug
Something developer should know.
UTILS_EX std::string hexify(std::string_view src, std::string_view pat)
URL hexify string.
std::vector< K > keys(const T &map)
Get keys from map.
Definition: gempyre_utils.h:547
std::string to_upper(const T &str)
make upper case string
Definition: gempyre_utils.h:436
std::variant< int, double, bool, std::string, std::nullptr_t, std::vector< std::any >, std::map< std::string, std::any >, std::unordered_map< std::string, std::any > > JsonType
Json Type.
Definition: gempyre_utils.h:916
Gempyre::dataT type
pixel type
Definition: gempyre_bitmap.h:36
Result is used like optional, but contains a fail reasoning.
Definition: gempyre_utils.h:249
E value_type
std compatibility
Definition: gempyre_utils.h:251
E error
error value
Definition: gempyre_utils.h:253
similar as std::optional, but with error info (not 100% same, add delta if needed).
Definition: gempyre_utils.h:257
constexpr Result(Err &&e)
Definition: gempyre_utils.h:270
constexpr const R & value() const
get value if available
Definition: gempyre_utils.h:300
constexpr static auto ok()
helper to make valid value, valid only if result has a default constructor
Definition: gempyre_utils.h:326
constexpr Result(const Err &e)
Definition: gempyre_utils.h:276
constexpr Result(R &&r)
Definition: gempyre_utils.h:267
constexpr Result & operator=(const R &r)
Definition: gempyre_utils.h:288
constexpr static auto make_error(E &&e)
helper to make error value
Definition: gempyre_utils.h:320
constexpr bool has_value() const
true is has value
Definition: gempyre_utils.h:298
constexpr R & value()
get value if available
Definition: gempyre_utils.h:304
E error_type
std compatibility
Definition: gempyre_utils.h:264
constexpr Result(const R &r)
Definition: gempyre_utils.h:273
constexpr static auto make_error(const E &e)
helper to make error value
Definition: gempyre_utils.h:316
R value_type
std compatibility
Definition: gempyre_utils.h:262
constexpr const E & error() const
get error if not value
Definition: gempyre_utils.h:302
constexpr static auto make_error()
helper to make error value, valid only if error has a default constructor
Definition: gempyre_utils.h:323
constexpr R * operator->()
get pointer to value
Definition: gempyre_utils.h:310
constexpr Result & operator=(Err &&e)
Definition: gempyre_utils.h:284
constexpr Result & operator=(R &&r)
Definition: gempyre_utils.h:280
constexpr R & operator*()
get ref to value
Definition: gempyre_utils.h:306
constexpr Result & operator=(const Err &e)
Definition: gempyre_utils.h:292