00001 /* ///////////////////////////////////////////////////////////////////////// 00002 * File: stlsoft/collections/functions.hpp 00003 * 00004 * Purpose: Collection manipulation functions. 00005 * 00006 * Created: 11th November 2004 00007 * Updated: 10th August 2009 00008 * 00009 * Home: http://stlsoft.org/ 00010 * 00011 * Copyright (c) 2004-2009, Matthew Wilson and Synesis Software 00012 * All rights reserved. 00013 * 00014 * Redistribution and use in source and binary forms, with or without 00015 * modification, are permitted provided that the following conditions are met: 00016 * 00017 * - Redistributions of source code must retain the above copyright notice, this 00018 * list of conditions and the following disclaimer. 00019 * - Redistributions in binary form must reproduce the above copyright notice, 00020 * this list of conditions and the following disclaimer in the documentation 00021 * and/or other materials provided with the distribution. 00022 * - Neither the name(s) of Matthew Wilson and Synesis Software nor the names of 00023 * any contributors may be used to endorse or promote products derived from 00024 * this software without specific prior written permission. 00025 * 00026 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00027 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00028 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00029 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 00030 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00031 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00032 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00033 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00034 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00035 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00036 * POSSIBILITY OF SUCH DAMAGE. 00037 * 00038 * ////////////////////////////////////////////////////////////////////// */ 00039 00040 00047 #ifndef STLSOFT_INCL_STLSOFT_COLLECTIONS_HPP_FUNCTIONS 00048 #define STLSOFT_INCL_STLSOFT_COLLECTIONS_HPP_FUNCTIONS 00049 00050 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION 00051 # define STLSOFT_VER_STLSOFT_COLLECTIONS_HPP_FUNCTIONS_MAJOR 2 00052 # define STLSOFT_VER_STLSOFT_COLLECTIONS_HPP_FUNCTIONS_MINOR 0 00053 # define STLSOFT_VER_STLSOFT_COLLECTIONS_HPP_FUNCTIONS_REVISION 3 00054 # define STLSOFT_VER_STLSOFT_COLLECTIONS_HPP_FUNCTIONS_EDIT 34 00055 #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */ 00056 00057 /* ///////////////////////////////////////////////////////////////////////// 00058 * Compatibility 00059 */ 00060 00061 /* 00062 [Incompatibilies-start] 00063 STLSOFT_COMPILER_IS_WATCOM: 00064 [Incompatibilies-end] 00065 */ 00066 00067 /* ///////////////////////////////////////////////////////////////////////// 00068 * Includes 00069 */ 00070 00071 #ifndef STLSOFT_INCL_STLSOFT_H_STLSOFT 00072 # include <stlsoft/stlsoft.h> 00073 #endif /* !STLSOFT_INCL_STLSOFT_H_STLSOFT */ 00074 #ifndef STLSOFT_INCL_STLSOFT_UTIL_STD_HPP_ITERATOR_HELPER 00075 # include <stlsoft/util/std/iterator_helper.hpp> 00076 #endif /* !STLSOFT_INCL_STLSOFT_UTIL_STD_HPP_ITERATOR_HELPER */ 00077 00078 #ifndef STLSOFT_INCL_STDEXCEPT 00079 # define STLSOFT_INCL_STDEXCEPT 00080 # include <stdexcept> 00081 #endif /* !STLSOFT_INCL_STDEXCEPT */ 00082 00083 #ifdef STLSOFT_UNITTEST 00084 # include <map> 00085 #endif /* STLSOFT_UNITTEST */ 00086 00087 /* ///////////////////////////////////////////////////////////////////////// 00088 * Namespace 00089 */ 00090 00091 #ifndef _STLSOFT_NO_NAMESPACE 00092 namespace stlsoft 00093 { 00094 #endif /* _STLSOFT_NO_NAMESPACE */ 00095 00096 /* ///////////////////////////////////////////////////////////////////////// 00097 * Compiler / library compatibility 00098 */ 00099 00100 #ifdef STLSOFT_CONTAINER_ACCESS_MAPPED_TYPE_IS_REFERENT_TYPE 00101 # undef STLSOFT_CONTAINER_ACCESS_MAPPED_TYPE_IS_REFERENT_TYPE 00102 #endif /* STLSOFT_CONTAINER_ACCESS_MAPPED_TYPE_IS_REFERENT_TYPE */ 00103 00104 #if defined(STLSOFT_CF_STD_LIBRARY_IS_DINKUMWARE_VC) 00105 # if STLSOFT_CF_STD_LIBRARY_DINKUMWARE_VC_VERSION <= STLSOFT_CF_DINKUMWARE_VC_VERSION_6_0 00106 # define STLSOFT_CONTAINER_ACCESS_MAPPED_TYPE_IS_REFERENT_TYPE 00107 # endif /* STLSOFT_CF_STD_LIBRARY_DINKUMWARE_VC_VERSION */ 00108 #endif /* STLSOFT_CF_STD_LIBRARY_IS_DINKUMWARE_VC */ 00109 00110 /* ///////////////////////////////////////////////////////////////////////// 00111 * Functions 00112 */ 00113 00127 #if ( !defined(STLSOFT_COMPILER_IS_INTEL) && \ 00128 !defined(STLSOFT_COMPILER_IS_MSVC)) || \ 00129 _MSC_VER >= 1310 00130 template< ss_typename_param_k M 00131 , ss_typename_param_k K 00132 > 00133 # ifdef STLSOFT_CONTAINER_ACCESS_MAPPED_TYPE_IS_REFERENT_TYPE 00134 inline ss_typename_type_ret_k M::referent_type &lookup(M &m, K const& key) 00135 # else /* ? STLSOFT_CONTAINER_ACCESS_MAPPED_TYPE_IS_REFERENT_TYPE */ 00136 inline ss_typename_type_ret_k M::mapped_type &lookup(M &m, K const& key) 00137 # endif /* STLSOFT_CONTAINER_ACCESS_MAPPED_TYPE_IS_REFERENT_TYPE */ 00138 { 00139 ss_typename_type_k M::iterator it = m.find(key); 00140 00141 if(m.end() == it) 00142 { 00143 STLSOFT_THROW_X(stlsoft_ns_qual_std(out_of_range)("invalid key")); 00144 } 00145 00146 return (*it).second; 00147 } 00148 #endif /* compiler */ 00149 00163 template< ss_typename_param_k M 00164 , ss_typename_param_k K 00165 > 00166 #ifdef STLSOFT_CONTAINER_ACCESS_MAPPED_TYPE_IS_REFERENT_TYPE 00167 inline ss_typename_type_ret_k M::referent_type const& lookup(M const& m, K const& key) 00168 #else /* ? STLSOFT_CONTAINER_ACCESS_MAPPED_TYPE_IS_REFERENT_TYPE */ 00169 inline ss_typename_type_ret_k M::mapped_type const& lookup(M const& m, K const& key) 00170 #endif /* STLSOFT_CONTAINER_ACCESS_MAPPED_TYPE_IS_REFERENT_TYPE */ 00171 { 00172 ss_typename_type_k M::const_iterator it = m.find(key); 00173 00174 if(m.end() == it) 00175 { 00176 STLSOFT_THROW_X(stlsoft_ns_qual_std(out_of_range)("invalid key")); 00177 } 00178 00179 return (*it).second; 00180 } 00181 00183 // Unit-testing 00184 00185 #ifdef STLSOFT_UNITTEST 00186 # include "./unittest/functions_unittest_.h" 00187 #endif /* STLSOFT_UNITTEST */ 00188 00189 /* ////////////////////////////////////////////////////////////////////// */ 00190 00191 #ifndef _STLSOFT_NO_NAMESPACE 00192 } // namespace stlsoft 00193 #endif /* _STLSOFT_NO_NAMESPACE */ 00194 00195 /* ////////////////////////////////////////////////////////////////////// */ 00196 00197 #endif /* !STLSOFT_INCL_STLSOFT_COLLECTIONS_HPP_FUNCTIONS */ 00198 00199 /* ///////////////////////////// end of file //////////////////////////// */