Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
SylvainCorlay committed Aug 12, 2020
1 parent 502a751 commit 6bebad1
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 additions & 16 deletions include/xwidgets/xeither.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,37 @@
#include <stdexcept>
#include <string>
#include <unordered_set>

#include "xtl/xoptional.hpp"

template <typename ... T>
auto XEITHER(T... vals) { \
const std::unordered_set<std::string> options({vals...});
return [options](const auto& proposal) {
auto position = options.find(proposal);
if (position == options.end()) {
auto XEITHER(T... vals)
{
const std::unordered_set<std::string> options({vals...});
return [options](const auto& proposal) {
auto position = options.find(proposal);
if (position == options.end())
{
throw std::runtime_error("Invalid proposal for string enum");
} \
};
}
};
}

template <typename ... T>
auto XEITHER_OPTIONAL(T...vals) {
auto XEITHER_OPTIONAL(T...vals)
{
const std::unordered_set<std::string> options({vals...});
return [options](const auto& proposal) {
if (xtl::has_value(proposal)) {
auto position = options.find(xtl::value(proposal));
if (position == options.end()) {
throw std::runtime_error("Invalid proposal for optional string enum");
}
}
};
return [options](const auto& proposal)
{
if (xtl::has_value(proposal))
{
auto position = options.find(xtl::value(proposal));
if (position == options.end())
{
throw std::runtime_error("Invalid proposal for optional string enum");
}
}
};
}

#endif

0 comments on commit 6bebad1

Please sign in to comment.