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
6#include <version>
7#ifndef MR_USE_STD_EXPECTED
8// #if __cpp_lib_expected >= 202211
9// Currently not using `std::expected` for simplicity, because:
10// 1. Clang 18 doesn't support libstdc++'s `std::expected`, which is a problem for the Python bindings. This got fixed in Clang 19.
11// 2. `MRMeshDotNet` can't use `std::expected` too.
12// In theory both can be fixed by defining `MR_DOT_NET_BUILD`.
13#define MR_USE_STD_EXPECTED 0
14#endif
15
16#if MR_USE_STD_EXPECTED
17#include <expected>
18#else
19#include <tl/expected.hpp>
22#ifdef MR_DOT_NET_BUILD
23namespace std
24{
25template<typename T, typename E>
26class expected : public tl::expected<T, E>
27{
28 using tl::expected<T, E>::expected;
29};
30
31template <class E>
32inline auto unexpected( E &&e )
33{
34 return tl::make_unexpected( std::forward<E>( e ) );
35}
36}
37#endif
38#endif
39
40#include <string>
41
42namespace MR
43{
44
45#if MR_USE_STD_EXPECTED || defined(MR_DOT_NET_BUILD)
46
47template<class T, class E = std::string>
48using Expected = std::expected<T, E>;
49
50template <class E>
51MR_BIND_IGNORE inline auto unexpected( E &&e )
52{
53 return std::unexpected( std::forward<E>( e ) );
54}
55
56#else
57
58template<class T, class E = std::string>
59using Expected = tl::expected<T, E>;
60
61template <class E>
62MR_BIND_IGNORE inline auto unexpected( E &&e )
63{
64 return tl::make_unexpected( std::forward<E>( e ) );
65}
66
67#endif
68
70MR_BIND_IGNORE inline std::string stringOperationCanceled()
71{
72 return "Operation was canceled";
73}
74
76MR_BIND_IGNORE inline auto unexpectedOperationCanceled()
77{
79}
80
82MR_BIND_IGNORE inline std::string stringUnsupportedFileExtension()
83{
84 return "Unsupported file extension";
85}
86
88MR_BIND_IGNORE inline auto unexpectedUnsupportedFileExtension()
89{
91}
92
93} //namespace MR
MR_BIND_IGNORE std::string stringUnsupportedFileExtension()
common message about unknown file extension
Definition MRExpected.h:82
MR_BIND_IGNORE auto unexpected(E &&e)
Definition MRExpected.h:62
tl::expected< T, E > Expected
Definition MRExpected.h:59
MR_BIND_IGNORE auto unexpectedUnsupportedFileExtension()
returns Expected error with stringUnsupportedFileExtension()
Definition MRExpected.h:88
MR_BIND_IGNORE auto unexpectedOperationCanceled()
returns Expected error with stringOperationCanceled()
Definition MRExpected.h:76
MR_BIND_IGNORE std::string stringOperationCanceled()
common message about user termination of an operation
Definition MRExpected.h:70