tinympl  0.2
mini MPL library for C++11
copy_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_COPY_IF_HPP
14 #define TINYMPL_VARIADIC_COPY_IF_HPP
15 
16 #include <type_traits>
17 
18 namespace tinympl {
19 namespace variadic {
20 
34 template< template<class ... T> class F,
35  template<class ...> class Out,
36  class ... Args> struct copy_if;
37 
38 template<template<class ... T> class F,
39  template<class ...> class Out,
40  class Head,
41  class ... Tail>
42 struct copy_if<F, Out, Head, Tail...> {
43 private:
44  template<class ... CopiedElements>
45  struct impl {
46  template<class ... Args>
47  using next = typename copy_if<F, Out, Tail...>::template
48  impl<CopiedElements..., Args...>;
49 
50  typedef typename std::conditional < F<Head>::type::value,
51  typename next<Head>::type,
52  typename next<>::type
53  >::type type;
54  };
55 
56  template<template<class ... T> class,
57  template<class ...> class,
58  class ...> friend struct copy_if;
59 
60 public:
61  typedef typename impl<>::type type;
62 };
63 
64 template<template<class ... T> class F, template<class ...> class Out>
65 struct copy_if<F, Out> {
66 private:
67  template<class ... CopiedElements>
68  struct impl {
69  typedef Out<CopiedElements...> type;
70  };
71 
72  template<template<class ... T> class, template<class ...> class, class ...>
73  friend struct copy_if;
74 
75 public:
76  typedef typename impl<>::type type;
77 };
78 
79 } // namespace variadic
80 } // namespace tinympl
81 
82 #endif // TINYMPL_VARIADIC_COPY_IF_HPP
Copy the elements of a given input sequence which satisfy a given predicate - the ordering is preserv...
Definition: copy_if.hpp:36
Copy the elements of a given input sequence which satisfy a given predicate - the ordering is preserv...
Definition: copy_if.hpp:37