示例#1
0
int main()
{
  std::cout << "4! = " ;
  constN<factorial(4)> out1; // computed at compile time

  volatile int k = 8;
  std::cout << k << "! = " << factorial(k) << '\n'; // computed at run time

  std::cout << "Number of lowercase letters in \"Hello, world!\" is ";
  constN<countlower("Hello, world!")> out2; // implicitly converted to conststr
}
示例#2
0
constexpr std::size_t countlower(conststr s, std::size_t n = 0,
    std::size_t c = 0) {
  return n == s.size() ? c :
    s[n] >= 'a' && s[n] <= 'z' ? countlower(s, n+1, c+1) :
    countlower(s, n+1, c);
}
示例#3
0
文件: main.cpp 项目: CCJY/coliru
int main()
{
    std::cout << "Number of lowercase letters in \"Hello, world!\" is ";
    constN<countlower("Hello, world!")>(); // implicitly converted to conststr
}