Skip to content

Instantly share code, notes, and snippets.

@loliGothicK
Created February 18, 2018 00:59
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 loliGothicK/e10be08f8eb43af910c6e5d23eb69b2a to your computer and use it in GitHub Desktop.
Save loliGothicK/e10be08f8eb43af910c6e5d23eb69b2a to your computer and use it in GitHub Desktop.
contexpr lambdaが一行で表現できないconstexpr variable templateの定義に使えそうとういうアレ
template<template <class> class Pred, typename ...Types>
constexpr inline std::size_t type_find_if = []
{
size_t result{};
for(bool b: {Pred<Types>::value...}) if(b) return result; else ++result;
return sizeof...(Types);
}();
int main() {
static_assert(type_find_if<std::is_unsigned, int, char, short, int, unsigned,long> == 4);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment