Skip to content

Commit

Permalink
Merge pull request #192 from joequant/dev/fix-crash-templatize
Browse files Browse the repository at this point in the history
fix to #191 by templatizing lambda
  • Loading branch information
JohanMabille committed Aug 11, 2020
2 parents 638e2ef + 579ec57 commit 502a751
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions include/xwidgets/xeither.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,30 @@
#include <stdexcept>
#include <string>
#include <unordered_set>

#include "xtl/xoptional.hpp"

#define XEITHER(...) \
[](const auto& proposal) { \
static const std::unordered_set<std::string> options({__VA_ARGS__}); \
auto position = options.find(proposal); \
if (position == options.end()) \
{ \
throw std::runtime_error("Invalid proposal for string enum"); \
} \
}
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()) {
throw std::runtime_error("Invalid proposal for string enum");
} \
};
}

#define XEITHER_OPTIONAL(...) \
[](const auto& proposal) { \
if (xtl::has_value(proposal)) \
{ \
static const std::unordered_set<std::string> options({__VA_ARGS__}); \
auto position = options.find(xtl::value(proposal)); \
if (position == options.end()) \
{ \
throw std::runtime_error("Invalid proposal for optional string enum"); \
} \
} \
}
template <typename ... T>
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");
}
}
};
}

#endif

0 comments on commit 502a751

Please sign in to comment.