diff --git a/include/boost/python/suite/indexing/algo_selector.hpp b/include/boost/python/suite/indexing/algo_selector.hpp new file mode 100755 index 00000000..5244fc77 --- /dev/null +++ b/include/boost/python/suite/indexing/algo_selector.hpp @@ -0,0 +1,186 @@ +// -*- mode:c++ -*- +// +// Header file algo_selector.hpp +// +// Automatic selection of container algorithms (and traits) for known +// container types (basically, all STL container instances, as well as +// iterator_pair instances). +// +// Copyright (c) 2003 Raoul M. Gough +// +// This material is provided "as is", with absolutely no warranty expressed +// or implied. Any use is at your own risk. +// +// Permission to use or copy this material for any purpose is hereby +// granted without fee, provided the above notices are retained on all +// copies. Permission to modify the material and to distribute modified +// versions is granted, provided the above notices are retained, and a +// notice that the material was modified is included with the above +// copyright notice. +// +// History +// ======= +// 2003/ 9/11 rmg File creation +// +// $Id$ +// + +#ifndef algo_selector_rmg_20030911_included +#define algo_selector_rmg_20030911_included + +#include "container_traits.hpp" +#include "algorithms.hpp" + +// Definitions of supported types +#include "iterator_pair.hpp" +#include +#include +#include +#include +#include + +namespace indexing { + ///////////////////////////////////////////////////////////////////////// + // Automated algorithm and trait selection + ///////////////////////////////////////////////////////////////////////// + + namespace detail { + template struct selector_impl; + + // selector_impl instances should include *two* publically + // accessible typedefs, one for the non-const version of the + // container, and one for the const version. This saves having to + // have two specializations of selector_impl for every kind of + // container. + + // std::set + template + class selector_impl > + { + typedef std::set Container; + + typedef set_traits mutable_traits; + typedef set_traits const_traits; + + public: + typedef assoc_algorithms mutable_algorithms; + typedef assoc_algorithms const_algorithms; + }; + + // std::multiset + template + class selector_impl > + { + typedef std::multiset Container; + + typedef set_traits mutable_traits; + typedef set_traits const_traits; + + public: + typedef assoc_algorithms mutable_algorithms; + typedef assoc_algorithms const_algorithms; + }; + + // std::map + template + class selector_impl > + { + typedef std::map Container; + + typedef map_traits mutable_traits; + typedef map_traits const_traits; + + public: + typedef assoc_algorithms mutable_algorithms; + typedef assoc_algorithms const_algorithms; + }; + + // std::multimap + template + class selector_impl > + { + typedef std::multimap Container; + + typedef map_traits mutable_traits; + typedef map_traits const_traits; + + public: + typedef assoc_algorithms mutable_algorithms; + typedef assoc_algorithms const_algorithms; + }; + + // std::vector + template + class selector_impl > + { + typedef std::vector Container; + + typedef default_sequence_traits mutable_traits; + typedef default_sequence_traits const_traits; + + public: + typedef default_algorithms mutable_algorithms; + typedef default_algorithms const_algorithms; + }; + + // std::deque + template + class selector_impl > + { + typedef std::deque Container; + + typedef default_sequence_traits mutable_traits; + typedef default_sequence_traits const_traits; + + public: + typedef default_algorithms mutable_algorithms; + typedef default_algorithms const_algorithms; + }; + + // std::list + template + class selector_impl > + { + typedef std::list Container; + + typedef default_sequence_traits mutable_traits; + typedef default_sequence_traits const_traits; + + public: + typedef list_algorithms mutable_algorithms; + typedef list_algorithms const_algorithms; + }; + + // Iterator ranges + template + class selector_impl > + { + typedef ::indexing::iterator_pair Container; + + typedef iterator_pair_traits mutable_traits; + typedef iterator_pair_traits const_traits; // ? + + public: + typedef default_algorithms mutable_algorithms; + typedef default_algorithms const_algorithms; + }; + } + + // Select the right algorithms for each supported kind of container + + // Generic version (mutable containers) + template + struct algo_selector + : public detail::selector_impl::mutable_algorithms + { + }; + + // Partial specialization for const containers + template + struct algo_selector + : public detail::selector_impl::const_algorithms + { + }; +} + +#endif // algo_selector_rmg_20030911_included