MeshLib C++ Docs
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#include "MRPch/MRExpected.h"
6#include <string>
7
8namespace MR
9{
12
13
14#if MR_USE_STD_EXPECTED || defined(MR_DOT_NET_BUILD)
15
16template<class T, class E = std::string>
17using Expected = std::expected<T, E>;
18
19template<class E = std::string>
20using Unexpected = std::unexpected<E>;
21
22template <class E>
23[[nodiscard]] MR_BIND_IGNORE inline auto unexpected( E &&e )
24{
25 return std::unexpected( std::forward<E>( e ) );
26}
27
28#else
29
30template<class T, class E = std::string>
31using Expected = tl::expected<T, E>;
32
33template<class E = std::string>
34using Unexpected = tl::unexpected<E>;
35
36template <class E>
37[[nodiscard]] MR_BIND_IGNORE inline auto unexpected( E &&e )
38{
39 return tl::make_unexpected( std::forward<E>( e ) );
40}
41
42#endif
43
45MR_BIND_IGNORE inline std::string stringOperationCanceled()
46{
47 return "Operation was canceled";
48}
49
51[[nodiscard]] MR_BIND_IGNORE inline auto unexpectedOperationCanceled()
52{
54}
55
57MR_BIND_IGNORE inline std::string stringUnsupportedFileExtension()
58{
59 return "Unsupported file extension";
60}
61
63[[nodiscard]] MR_BIND_IGNORE inline auto unexpectedUnsupportedFileExtension()
64{
66}
67
69MR_BIND_IGNORE inline std::string stringUnsupportedFileFormat()
70{
71 return "Unsupported file format";
72}
73
75[[nodiscard]] MR_BIND_IGNORE inline auto unexpectedUnsupportedFileFormat()
76{
78}
79
81#define MR_RETURN_IF_UNEXPECTED( expr ) \
82 if ( auto&& res = ( expr ); !res ) \
83 return unexpected( std::move( res.error() ) );
84
85}
auto unexpectedUnsupportedFileFormat()
returns Expected error with stringUnsupportedFileFormat()
Definition MRExpected.h:75
std::string stringOperationCanceled()
common message about user termination of an operation
Definition MRExpected.h:45
std::string stringUnsupportedFileFormat()
common message prefix about unsupported file format
Definition MRExpected.h:69
tl::expected< T, E > Expected
Definition MRExpected.h:31
tl::unexpected< E > Unexpected
Definition MRExpected.h:34
std::string stringUnsupportedFileExtension()
common message about unknown file extension
Definition MRExpected.h:57
auto unexpected(E &&e)
Definition MRExpected.h:37
auto unexpectedUnsupportedFileExtension()
returns Expected error with stringUnsupportedFileExtension()
Definition MRExpected.h:63
auto unexpectedOperationCanceled()
returns Expected error with stringOperationCanceled()
Definition MRExpected.h:51
Only strictly necessary for the bindings (to make MR::MeshIntersectionResult a complete type).
Definition MRCameraOrientationPlugin.h:8