tinympl  0.2
mini MPL library for C++11
count_if.hpp
1 // Copyright (C) 2013, Ennio Barbaro.
2 //
3 // Use, modification, and distribution is subject to the Boost Software
4 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
6 //
7 // See http://sbabbi.github.io/tinympl for documentation.
8 //
9 // You are welcome to contact the author at:
10 // enniobarbaro@gmail.com
11 //
12 
13 #ifndef TINYMPL_VARIADIC_COUNT_IF_HPP
14 #define TINYMPL_VARIADIC_COUNT_IF_HPP
15 
16 #include <type_traits>
17 #include <cstddef>
18 
19 namespace tinympl {
20 namespace variadic {
21 
33 template<template<class ... T> class F, class ... Args> struct count_if;
34 
35 template<template<class ... T> class F, class Head, class ... Tail>
36 struct count_if<F, Head, Tail...> :
37  std::integral_constant < std::size_t,
38  count_if<F, Tail...>::type::value +
39 ( F<Head>::type::value ? 1 : 0 ) >
40 {};
41 
42 template<template<class ... T> class F> struct count_if<F> :
43  std::integral_constant<std::size_t, 0>
44 {};
45 
46 } // namespace variadic
47 } // namespace tinympl
48 
49 #endif // TINYMPL_VARIADIC_COUNT_IF_HPP
Counts the number of elements which satisfy a given predicate.
Definition: count_if.hpp:33