1/* Copyright 2003-2008 Joaquin M Lopez Munoz.
2 * Distributed under the Boost Software License, Version 1.0.
3 * (See accompanying file LICENSE_1_0.txt or copy at
4 * http://www.boost.org/LICENSE_1_0.txt)
5 *
6 * See http://www.boost.org/libs/multi_index for library home page.
7 */
8
9#ifndef BOOST_MULTI_INDEX_DETAIL_HEADER_HOLDER_HPP
10#define BOOST_MULTI_INDEX_DETAIL_HEADER_HOLDER_HPP
11
12#if defined(_MSC_VER)
13#pragma once
14#endif
15
16#include <boost/noncopyable.hpp>
17
18namespace boost{
19
20namespace multi_index{
21
22namespace detail{
23
24/* A utility class used to hold a pointer to the header node.
25 * The base from member idiom is used because index classes, which are
26 * superclasses of multi_index_container, need this header in construction
27 * time. The allocation is made by the allocator of the multi_index_container
28 * class --hence, this allocator needs also be stored resorting
29 * to the base from member trick.
30 */
31
32template<typename NodeTypePtr,typename Final>
33struct header_holder:private noncopyable
34{
35 header_holder():member(final().allocate_node()){}
36 ~header_holder(){final().deallocate_node(&*member);}
37
38 NodeTypePtr member;
39
40private:
41 Final& final(){return *static_cast<Final*>(this);}
42};
43
44} /* namespace multi_index::detail */
45
46} /* namespace multi_index */
47
48} /* namespace boost */
49
50#endif
51