Last active
February 6, 2018 12:34
-
-
Save sithhell/adef84a489688913198fde67ef4235a2 to your computer and use it in GitHub Desktop.
Outcome ODR
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "A.hpp" | |
namespace A | |
{ | |
A::result foo() | |
{ | |
return 5; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <outcome.hpp> | |
namespace A | |
{ | |
namespace outcome = OUTCOME_V2_NAMESPACE; | |
struct my_error {}; | |
using result = outcome::result<int, my_error>; | |
A::result foo(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "B.hpp" | |
#include "A.hpp" | |
OUTCOME_V2_NAMESPACE_BEGIN | |
namespace convert | |
{ | |
template <> | |
struct value_or_error<::B::result, ::A::result> | |
{ | |
// True to indicate that this converter wants `result`/`outcome` to NOT reject all other `result` | |
static constexpr bool enable_result_inputs = true; | |
// False to indicate that this converter wants `outcome` to NOT reject all other `outcome` | |
static constexpr bool enable_outcome_inputs = false; | |
::B::result operator()(::A::result &&src) | |
{ | |
return 5; | |
} | |
}; | |
} | |
OUTCOME_V2_NAMESPACE_END | |
namespace B | |
{ | |
result foo() | |
{ | |
return B::result(A::foo()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <outcome.hpp> | |
namespace B | |
{ | |
namespace outcome = OUTCOME_V2_NAMESPACE; | |
using result = outcome::result<int>; | |
B::result foo(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "C.hpp" | |
#include "A.hpp" | |
OUTCOME_V2_NAMESPACE_BEGIN | |
namespace convert | |
{ | |
template <> | |
struct value_or_error<::C::result, ::A::result> | |
{ | |
// True to indicate that this converter wants `result`/`outcome` to NOT reject all other `result` | |
static constexpr bool enable_result_inputs = true; | |
// False to indicate that this converter wants `outcome` to NOT reject all other `outcome` | |
static constexpr bool enable_outcome_inputs = false; | |
::C::result operator()(::A::result &&src) | |
{ | |
return 42; | |
} | |
}; | |
} | |
OUTCOME_V2_NAMESPACE_END | |
namespace C | |
{ | |
result foo() | |
{ | |
return C::result(A::foo()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <outcome.hpp> | |
namespace C | |
{ | |
namespace outcome = OUTCOME_V2_NAMESPACE; | |
using result = outcome::result<int>; | |
C::result foo(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "B.hpp" | |
#include "C.hpp" | |
#include <iostream> | |
int main() | |
{ | |
{ | |
auto r = B::foo(); | |
std::cout << r.value() << '\n'; | |
} | |
{ | |
auto r = C::foo(); | |
std::cout << r.value() << '\n'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment