Skip to content

Instantly share code, notes, and snippets.

@sithhell
Last active February 6, 2018 12:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sithhell/adef84a489688913198fde67ef4235a2 to your computer and use it in GitHub Desktop.
Save sithhell/adef84a489688913198fde67ef4235a2 to your computer and use it in GitHub Desktop.
Outcome ODR
#include "A.hpp"
namespace A
{
A::result foo()
{
return 5;
}
}
#include <outcome.hpp>
namespace A
{
namespace outcome = OUTCOME_V2_NAMESPACE;
struct my_error {};
using result = outcome::result<int, my_error>;
A::result foo();
}
#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());
}
}
#include <outcome.hpp>
namespace B
{
namespace outcome = OUTCOME_V2_NAMESPACE;
using result = outcome::result<int>;
B::result foo();
}
#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());
}
}
#include <outcome.hpp>
namespace C
{
namespace outcome = OUTCOME_V2_NAMESPACE;
using result = outcome::result<int>;
C::result foo();
}
#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