Exemplo n.º 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
}
Exemplo n.º 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);
}
Exemplo n.º 3
0
Arquivo: main.cpp Projeto: CCJY/coliru
int main()
{
    std::cout << "Number of lowercase letters in \"Hello, world!\" is ";
    constN<countlower("Hello, world!")>(); // implicitly converted to conststr
}