1 /* Copyright 2006-2009 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/flyweight for library home page. 7 */ 8 9 #ifndef BOOST_FLYWEIGHT_STATIC_HOLDER_HPP 10 #define BOOST_FLYWEIGHT_STATIC_HOLDER_HPP 11 12 #if defined(_MSC_VER) 13 #pragma once 14 #endif 15 16 #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */ 17 #include <boost/flyweight/static_holder_fwd.hpp> 18 #include <boost/flyweight/holder_tag.hpp> 19 #include <boost/mpl/aux_/lambda_support.hpp> 20 21 /* Simplest holder storing the T object as a local static variable. 22 */ 23 24 namespace boost{ 25 26 namespace flyweights{ 27 28 template<typename C> 29 struct static_holder_class:holder_marker 30 { getboost::flyweights::static_holder_class31 static C& get() 32 { 33 static C c; 34 return c; 35 } 36 37 typedef static_holder_class type; 38 BOOST_MPL_AUX_LAMBDA_SUPPORT(1,static_holder_class,(C)) 39 }; 40 41 /* static_holder_class specifier */ 42 43 struct static_holder:holder_marker 44 { 45 template<typename C> 46 struct apply 47 { 48 typedef static_holder_class<C> type; 49 }; 50 }; 51 52 } /* namespace flyweights */ 53 54 } /* namespace boost */ 55 56 #endif 57