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{
10
11#if MR_USE_STD_EXPECTED || defined(MR_DOT_NET_BUILD)
12
13template<class T, class E = std::string>
14using Expected = std::expected<T, E>;
15
16template<class E = std::string>
17using Unexpected = std::unexpected<E>;
18
19template <class E>
20MR_BIND_IGNORE inline auto unexpected( E &&e )
21{
22 return std::unexpected( std::forward<E>( e ) );
23}
24
25#else
26
27template<class T, class E = std::string>
28using Expected = tl::expected<T, E>;
29
30template<class E = std::string>
31using Unexpected = tl::unexpected<E>;
32
33template <class E>
34MR_BIND_IGNORE inline auto unexpected( E &&e )
35{
36 return tl::make_unexpected( std::forward<E>( e ) );
37}
38
39#endif
40
43{
44 return "Operation was canceled";
45}
46
52
55{
56 return "Unsupported file extension";
57}
58
64
67{
68 return "Unsupported file format";
69}
70
76
78#define MR_RETURN_IF_UNEXPECTED( expr ) \
79 if ( auto&& res = ( expr ); !res ) \
80 return unexpected( std::move( res.error() ) );
81
82} //namespace MR
Definition MRCameraOrientationPlugin.h:8
MR_BIND_IGNORE std::string stringUnsupportedFileExtension()
common message about unknown file extension
Definition MRExpected.h:54
MR_BIND_IGNORE auto unexpected(E &&e)
Definition MRExpected.h:34
tl::expected< T, E > Expected
Definition MRExpected.h:28
MR_BIND_IGNORE auto unexpectedUnsupportedFileExtension()
returns Expected error with stringUnsupportedFileExtension()
Definition MRExpected.h:60
MR_BIND_IGNORE auto unexpectedUnsupportedFileFormat()
returns Expected error with stringUnsupportedFileFormat()
Definition MRExpected.h:72
MR_BIND_IGNORE auto unexpectedOperationCanceled()
returns Expected error with stringOperationCanceled()
Definition MRExpected.h:48
tl::unexpected< E > Unexpected
Definition MRExpected.h:31
std::array< Vector3f, 3 > MR_BIND_IGNORE
Definition MRMeshBuilderTypes.h:10
MR_BIND_IGNORE std::string stringUnsupportedFileFormat()
common message prefix about unsupported file format
Definition MRExpected.h:66
MR_BIND_IGNORE std::string stringOperationCanceled()
common message about user termination of an operation
Definition MRExpected.h:42