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