Spatial C++ Library
Generic Multi-Dimensional Containers and Spatial Operations
spatial_compress.hpp
1 // -*- C++ -*-
2 //
3 // Copyright Sylvain Bougerel 2009 - 2013.
4 // Distributed under the Boost Software License, Version 1.0.
5 // (See accompanying file COPYING or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7 
15 #ifndef SPATIAL_COMPRESS_HPP
16 #define SPATIAL_COMPRESS_HPP
17 
18 namespace spatial
19 {
32  namespace details
33  {
45  template<typename Base, typename Member>
46  struct Compress
47  : private Base // Empty member optimization
48  {
50  Compress() { }
51 
54  explicit Compress(const Base& compressed_base)
55  : Base(compressed_base), _member() { }
56 
60  Compress(const Base& compressed_base, const Member& member)
61  : Base(compressed_base), _member(member) { }
62 
66  const Base&
68  base() const
69  { return *static_cast<const Base*>(this); }
70 
71  Base&
72  base()
73  { return *static_cast<Base*>(this); }
75 
79  const Member&
81  operator()() const
82  { return _member; }
83 
84  Member&
86  { return _member; }
88 
89  private:
91  Member _member;
92  };
93  } // namespace details
94 } // namespace spatial
95 
96 #endif // SPATIAL_COMPRESS_HPP
const Member & operator()() const
Quick accessor to the member.
Member & operator()()
Quick accessor to the member.
Member _member
Storage for the member value.
Base & base()
Accessor to the base class.
Uses the empty base class optimization in order to compress a potentially empty base class with a mem...
The main namespace used in the library.
Definition: algorithm.hpp:23
const Base & base() const
Accessor to the base class.
Compress(const Base &compressed_base)
Compressed member with uninitialized base.
Compress()
Uninitialized compressed base.
Compress(const Base &compressed_base, const Member &member)
Standard initializer with Base and Member values.