tinympl  0.2
mini MPL library for C++11
copy_n.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_N_HPP
14 #define TINYMPL_VARIADIC_COPY_N_HPP
15 
16 #include <cstddef>
17 
18 namespace tinympl {
19 namespace variadic {
20 
33 template<std::size_t n, template<class ...> class Out, class ... Args>
34 struct copy_n;
35 
36 template<std::size_t n,
37  template<class ...> class Out,
38  class Head, class ... Tail>
39 struct copy_n<n, Out, Head, Tail...> {
40 private:
41  template<class ... CopiedElements> struct impl {
42  typedef typename copy_n < n - 1, Out, Tail... >::template
43  impl<CopiedElements..., Head>::type type;
44  };
45 
46  template<std::size_t, template<class ...> class, class ...>
47  friend struct copy_n;
48 
49 public:
50  static_assert( n <= 1 + sizeof...( Tail ), "n overflow" );
51  typedef typename impl<>::type type;
52 };
53 
54 template<template<class ...> class Out, class Head, class ... Tail>
55 struct copy_n<0, Out, Head, Tail...> {
56 private:
57  template<class ... CopiedElements> struct impl {
58  typedef Out<CopiedElements...> type;
59  };
60 
61  template<std::size_t, template<class ...> class, class ...>
62  friend struct copy_n;
63 
64 public:
65  typedef typename impl<>::type type;
66 };
67 
68 template<template<class ...> class Out> struct copy_n<0, Out> {
69 private:
70  template<class ... CopiedElements> struct impl {
71  typedef Out<CopiedElements...> type;
72  };
73 
74  template<std::size_t, template<class ...> class, class ...>
75  friend struct copy_n;
76 
77 public:
78  typedef typename impl<>::type type;
79 };
80 
81 
82 } // namespace variadic
83 } // namespace tinympl
84 
85 #endif // TINYMPL_VARIADIC_COPY_N_HPP
Copy the first N elements from the input sequence.
Definition: copy_n.hpp:37
Copy the first n elements from the input sequence.
Definition: copy_n.hpp:34