MeshLib Documentation
Loading...
Searching...
No Matches
MRExpected.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRMeshFwd.h"
4#include "MRPch/MRBindingMacros.h"
5
6#include <version>
7#ifndef MR_USE_STD_EXPECTED
8#if __cpp_lib_expected >= 202211
9#define MR_USE_STD_EXPECTED 1
10#else
11#define MR_USE_STD_EXPECTED 0
12#endif
13#endif
14
15#if MR_USE_STD_EXPECTED
16#include <expected>
17#else
18#include <tl/expected.hpp>
21#ifdef MR_DOT_NET_BUILD
22namespace std
23{
24template<typename T, typename E>
25class expected : public tl::expected<T, E>
26{
27 using tl::expected<T, E>::expected;
28};
29
30template <class E>
31inline auto unexpected( E &&e )
32{
33 return tl::make_unexpected( std::forward<E>( e ) );
34}
35}
36#endif
37#endif
38
39#include <string>
40
41namespace MR
42{
43
44#if MR_USE_STD_EXPECTED || defined(MR_DOT_NET_BUILD)
45
46template<class T, class E = std::string>
47using Expected = std::expected<T, E>;
48
49template <class E>
50MR_BIND_IGNORE inline auto unexpected( E &&e )
51{
52 return std::unexpected( std::forward<E>( e ) );
53}
54
55#else
56
57template<class T, class E = std::string>
58using Expected = tl::expected<T, E>;
59
60template <class E>
61MR_BIND_IGNORE inline auto unexpected( E &&e )
62{
63 return tl::make_unexpected( std::forward<E>( e ) );
64}
65
66#endif
67
69using VoidOrErrStr [[deprecated]] = Expected<void>;
70
72MR_BIND_IGNORE inline std::string stringOperationCanceled()
73{
74 return "Operation was canceled";
75}
76
78MR_BIND_IGNORE inline auto unexpectedOperationCanceled()
79{
81}
82
83} //namespace MR
Definition MRCameraOrientationPlugin.h:8
MR_BIND_IGNORE auto unexpected(E &&e)
Definition MRExpected.h:61
tl::expected< T, E > Expected
Definition MRExpected.h:58
MR_BIND_IGNORE auto unexpectedOperationCanceled()
Returns Expected error with stringOperationCanceled()
Definition MRExpected.h:78
MR_BIND_IGNORE std::string stringOperationCanceled()
Common operation canceled line for all.
Definition MRExpected.h:72