Gobelijn API documentation  - generated for commit a0cbea7
 All Classes Namespaces Files Functions Variables Typedefs Friends Macros Pages
small2.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of the gobelijn software.
3  * Gobelijn is free software: you can redistribute it and/or modify it
4  * under the terms of the GNU General Public License as published by the
5  * Free Software Foundation, either version 3 of the License, or any later
6  * version. Gobelijn is distributed in the hope that it will be useful, but
7  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
8  * or FITNESS FOR A PARTICULAR PURPOSE.
9  * See the GNU General Public License for details. You should have received
10  * a copy of the GNU General Public License along with the software. If not,
11  * see <http://www.gnu.org/licenses/>.
12  *
13  * Copyright 2012, Jan Broeckhove.
14  */
20 // BEGIN_SNIPPET{FullSource}
21 #include "smaller.h"
22 #include <cstddef>
23 #include <vector>
24 
25 using namespace std;
26 
27 namespace {
28 
32 template <typename T1, typename T2>
33 class pack_for_file_storage
34 {
35 public:
36  using pack_type = typename smaller<T1, T2>::type;
37 
38 public:
39  explicit pack_for_file_storage(size_t s) : m_data(s) {};
40  void pack(T1 t1, size_t i) { m_data[i] = static_cast<pack_type>(t1); }
41  void pack(T2 t2, size_t i) { m_data[i] = static_cast<pack_type>(t2); };
42  pack_type peek(size_t i) const { return m_data[i]; }
43 
44 private:
45  vector<pack_type> m_data;
46 };
47 
48 } // namespace
49 
50 int main()
51 {
52  pack_for_file_storage<float, long> pp{100};
53  pack_for_file_storage<float, long>::pack_type p;
54  p = pp.peek(3);
55  pp.pack(5.0f, 4);
56  pp.pack(1l, 6);
57  pp.pack(p, 1);
58  //...
59  return 0;
60 }
61 // END_SNIPPET{FullSource}
int main()
Definition: small2.cpp:50
typename select< T1, T2,(sizeof(T1)< sizeof(T2))>::type type
Definition: smaller.h:30
Compute type with smallest memory size.