Merge branch 'cpp-11' into save_ext
This commit is contained in:
		@@ -1524,8 +1524,11 @@ make_cflags_and_ldflags() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		cc_build_is_gcc=`basename "$cc_build" | grep "gcc" 2>/dev/null`
 | 
							cc_build_is_gcc=`basename "$cc_build" | grep "gcc" 2>/dev/null`
 | 
				
			||||||
		if [ -n "$cc_build_is_gcc" ]; then
 | 
							if [ -n "$cc_build_is_gcc" ]; then
 | 
				
			||||||
			# Just add -O1 to the tools needed for building.
 | 
								# Add -O1 and fortify source to the tools needed for building, on gcc
 | 
				
			||||||
			CFLAGS_BUILD="$CFLAGS_BUILD -D_FORTIFY_SOURCE=2 -O1"
 | 
								CFLAGS_BUILD="$CFLAGS_BUILD -D_FORTIFY_SOURCE=2 -O1"
 | 
				
			||||||
 | 
							elif [ -n "`basename "$cc_build" | grep "clang" 2>/dev/null`" ]; then
 | 
				
			||||||
 | 
								# Add -O1 to the tools needed for building, on clang
 | 
				
			||||||
 | 
								CFLAGS_BUILD="$CFLAGS_BUILD -O1"
 | 
				
			||||||
		fi
 | 
							fi
 | 
				
			||||||
	fi
 | 
						fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -423,6 +423,7 @@ core/alloc_type.hpp
 | 
				
			|||||||
core/backup_type.hpp
 | 
					core/backup_type.hpp
 | 
				
			||||||
core/bitmath_func.cpp
 | 
					core/bitmath_func.cpp
 | 
				
			||||||
core/bitmath_func.hpp
 | 
					core/bitmath_func.hpp
 | 
				
			||||||
 | 
					core/container_func.hpp
 | 
				
			||||||
core/endian_func.hpp
 | 
					core/endian_func.hpp
 | 
				
			||||||
core/endian_type.hpp
 | 
					core/endian_type.hpp
 | 
				
			||||||
core/enum_type.hpp
 | 
					core/enum_type.hpp
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										35
									
								
								src/core/container_func.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								src/core/container_func.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,35 @@
 | 
				
			|||||||
 | 
					/* $Id$ */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * This file is part of OpenTTD.
 | 
				
			||||||
 | 
					 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
 | 
				
			||||||
 | 
					 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 | 
				
			||||||
 | 
					 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** @file container_func.hpp Functions related to use of containers. */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					template <typename C, typename UP> unsigned int container_unordered_remove_if (C &container, UP predicate) {
 | 
				
			||||||
 | 
						unsigned int removecount = 0;
 | 
				
			||||||
 | 
						for (auto it = container.begin(); it != container.end();) {
 | 
				
			||||||
 | 
							if (predicate(*it)) {
 | 
				
			||||||
 | 
								removecount++;
 | 
				
			||||||
 | 
								if (std::next(it) != container.end()) {
 | 
				
			||||||
 | 
									*it = std::move(container.back());
 | 
				
			||||||
 | 
									container.pop_back();
 | 
				
			||||||
 | 
								} else {
 | 
				
			||||||
 | 
									container.pop_back();
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								++it;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return removecount;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					template <typename C, typename V> unsigned int container_unordered_remove(C &container, const V &value) {
 | 
				
			||||||
 | 
						return container_unordered_remove_if (container, [&](const typename C::value_type &v) {
 | 
				
			||||||
 | 
							return v == value;
 | 
				
			||||||
 | 
						});
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -15,7 +15,7 @@
 | 
				
			|||||||
#include <map>
 | 
					#include <map>
 | 
				
			||||||
#include <list>
 | 
					#include <list>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
template<typename Tkey, typename Tvalue, typename Tcompare>
 | 
					template<typename Tkey, typename Tvalue, typename Tcontainer, typename Tcompare>
 | 
				
			||||||
class MultiMap;
 | 
					class MultiMap;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
@@ -23,14 +23,15 @@ class MultiMap;
 | 
				
			|||||||
 * @tparam Tmap_iter Iterator type for the map in the MultiMap.
 | 
					 * @tparam Tmap_iter Iterator type for the map in the MultiMap.
 | 
				
			||||||
 * @tparam Tlist_iter Iterator type for the lists in the MultiMap.
 | 
					 * @tparam Tlist_iter Iterator type for the lists in the MultiMap.
 | 
				
			||||||
 * @tparam Tkey Key type of the MultiMap.
 | 
					 * @tparam Tkey Key type of the MultiMap.
 | 
				
			||||||
 * @tparam Tvalue Value type of the MultMap.
 | 
					 * @tparam Tvalue Value type of the MultiMap.
 | 
				
			||||||
 | 
					 * @tparam Tcontainer Container type for the values of the MultiMap.
 | 
				
			||||||
 * @tparam Tcompare Comparator type for keys of the MultiMap.
 | 
					 * @tparam Tcompare Comparator type for keys of the MultiMap.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
template<class Tmap_iter, class Tlist_iter, class Tkey, class Tvalue, class Tcompare>
 | 
					template<class Tmap_iter, class Tlist_iter, class Tkey, class Tvalue, class Tcontainer, class Tcompare>
 | 
				
			||||||
class MultiMapIterator {
 | 
					class MultiMapIterator {
 | 
				
			||||||
protected:
 | 
					protected:
 | 
				
			||||||
	friend class MultiMap<Tkey, Tvalue, Tcompare>;
 | 
						friend class MultiMap<Tkey, Tvalue, Tcontainer, Tcompare>;
 | 
				
			||||||
	typedef MultiMapIterator<Tmap_iter, Tlist_iter, Tkey, Tvalue, Tcompare> Self;
 | 
						typedef MultiMapIterator<Tmap_iter, Tlist_iter, Tkey, Tvalue, Tcontainer, Tcompare> Self;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	Tlist_iter list_iter; ///< Iterator pointing to current position in the current list of items with equal keys.
 | 
						Tlist_iter list_iter; ///< Iterator pointing to current position in the current list of items with equal keys.
 | 
				
			||||||
	Tmap_iter map_iter;   ///< Iterator pointing to the position of the current list of items with equal keys in the map.
 | 
						Tmap_iter map_iter;   ///< Iterator pointing to the position of the current list of items with equal keys in the map.
 | 
				
			||||||
@@ -201,8 +202,8 @@ public:
 | 
				
			|||||||
 * @param iter2 Second iterator to compare.
 | 
					 * @param iter2 Second iterator to compare.
 | 
				
			||||||
 * @return If iter1 and iter2 are equal.
 | 
					 * @return If iter1 and iter2 are equal.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
template<class Tmap_iter1, class Tlist_iter1, class Tmap_iter2, class Tlist_iter2, class Tkey, class Tvalue1, class Tvalue2, class Tcompare>
 | 
					template<class Tmap_iter1, class Tlist_iter1, class Tmap_iter2, class Tlist_iter2, class Tkey, class Tvalue1, class Tvalue2, class Tcontainer1, class Tcontainer2, class Tcompare>
 | 
				
			||||||
bool operator==(const MultiMapIterator<Tmap_iter1, Tlist_iter1, Tkey, Tvalue1, Tcompare> &iter1, const MultiMapIterator<Tmap_iter2, Tlist_iter2, Tkey, Tvalue2, Tcompare> &iter2)
 | 
					bool operator==(const MultiMapIterator<Tmap_iter1, Tlist_iter1, Tkey, Tvalue1, Tcontainer1, Tcompare> &iter1, const MultiMapIterator<Tmap_iter2, Tlist_iter2, Tkey, Tvalue2, Tcontainer2, Tcompare> &iter2)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	if (iter1.GetMapIter() != iter2.GetMapIter()) return false;
 | 
						if (iter1.GetMapIter() != iter2.GetMapIter()) return false;
 | 
				
			||||||
	if (!iter1.ListValid()) return !iter2.ListValid();
 | 
						if (!iter1.ListValid()) return !iter2.ListValid();
 | 
				
			||||||
@@ -218,8 +219,8 @@ bool operator==(const MultiMapIterator<Tmap_iter1, Tlist_iter1, Tkey, Tvalue1, T
 | 
				
			|||||||
 * @param iter2 Second iterator to compare.
 | 
					 * @param iter2 Second iterator to compare.
 | 
				
			||||||
 * @return If iter1 and iter2 are not equal.
 | 
					 * @return If iter1 and iter2 are not equal.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
template<class Tmap_iter1, class Tlist_iter1, class Tmap_iter2, class Tlist_iter2, class Tkey, class Tvalue1, class Tvalue2, class Tcompare>
 | 
					template<class Tmap_iter1, class Tlist_iter1, class Tmap_iter2, class Tlist_iter2, class Tkey, class Tvalue1, class Tvalue2, class Tcontainer1, class Tcontainer2, class Tcompare>
 | 
				
			||||||
bool operator!=(const MultiMapIterator<Tmap_iter1, Tlist_iter1, Tkey, Tvalue1, Tcompare> &iter1, const MultiMapIterator<Tmap_iter2, Tlist_iter2, Tkey, Tvalue2, Tcompare> &iter2)
 | 
					bool operator!=(const MultiMapIterator<Tmap_iter1, Tlist_iter1, Tkey, Tvalue1, Tcontainer1, Tcompare> &iter1, const MultiMapIterator<Tmap_iter2, Tlist_iter2, Tkey, Tvalue2, Tcontainer2, Tcompare> &iter2)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	return !(iter1 == iter2);
 | 
						return !(iter1 == iter2);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -232,8 +233,8 @@ bool operator!=(const MultiMapIterator<Tmap_iter1, Tlist_iter1, Tkey, Tvalue1, T
 | 
				
			|||||||
 * @param iter2 Map iterator.
 | 
					 * @param iter2 Map iterator.
 | 
				
			||||||
 * @return If iter1 points to the begin of the list pointed to by iter2.
 | 
					 * @return If iter1 points to the begin of the list pointed to by iter2.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
template<class Tmap_iter1, class Tlist_iter1, class Tmap_iter2, class Tkey, class Tvalue, class Tcompare >
 | 
					template<class Tmap_iter1, class Tlist_iter1, class Tmap_iter2, class Tkey, class Tvalue, class Tcontainer, class Tcompare >
 | 
				
			||||||
bool operator==(const MultiMapIterator<Tmap_iter1, Tlist_iter1, Tkey, Tvalue, Tcompare> &iter1, const Tmap_iter2 &iter2)
 | 
					bool operator==(const MultiMapIterator<Tmap_iter1, Tlist_iter1, Tkey, Tvalue, Tcontainer, Tcompare> &iter1, const Tmap_iter2 &iter2)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	return !iter1.ListValid() && iter1.GetMapIter() == iter2;
 | 
						return !iter1.ListValid() && iter1.GetMapIter() == iter2;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -244,8 +245,8 @@ bool operator==(const MultiMapIterator<Tmap_iter1, Tlist_iter1, Tkey, Tvalue, Tc
 | 
				
			|||||||
 * @param iter2 Map iterator.
 | 
					 * @param iter2 Map iterator.
 | 
				
			||||||
 * @return If iter1 doesn't point to the begin of the list pointed to by iter2.
 | 
					 * @return If iter1 doesn't point to the begin of the list pointed to by iter2.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
template<class Tmap_iter1, class Tlist_iter1, class Tmap_iter2, class Tkey, class Tvalue, class Tcompare >
 | 
					template<class Tmap_iter1, class Tlist_iter1, class Tmap_iter2, class Tkey, class Tvalue, class Tcontainer, class Tcompare >
 | 
				
			||||||
bool operator!=(const MultiMapIterator<Tmap_iter1, Tlist_iter1, Tkey, Tvalue, Tcompare> &iter1, const Tmap_iter2 &iter2)
 | 
					bool operator!=(const MultiMapIterator<Tmap_iter1, Tlist_iter1, Tkey, Tvalue, Tcontainer, Tcompare> &iter1, const Tmap_iter2 &iter2)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	return iter1.ListValid() || iter1.GetMapIter() != iter2;
 | 
						return iter1.ListValid() || iter1.GetMapIter() != iter2;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -256,8 +257,8 @@ bool operator!=(const MultiMapIterator<Tmap_iter1, Tlist_iter1, Tkey, Tvalue, Tc
 | 
				
			|||||||
 * @param iter1 MultiMap iterator.
 | 
					 * @param iter1 MultiMap iterator.
 | 
				
			||||||
 * @return If iter1 points to the begin of the list pointed to by iter2.
 | 
					 * @return If iter1 points to the begin of the list pointed to by iter2.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
template<class Tmap_iter1, class Tlist_iter1, class Tmap_iter2, class Tkey, class Tvalue, class Tcompare >
 | 
					template<class Tmap_iter1, class Tlist_iter1, class Tmap_iter2, class Tkey, class Tvalue, class Tcontainer, class Tcompare >
 | 
				
			||||||
bool operator==(const Tmap_iter2 &iter2, const MultiMapIterator<Tmap_iter1, Tlist_iter1, Tkey, Tvalue, Tcompare> &iter1)
 | 
					bool operator==(const Tmap_iter2 &iter2, const MultiMapIterator<Tmap_iter1, Tlist_iter1, Tkey, Tvalue, Tcontainer, Tcompare> &iter1)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	return !iter1.ListValid() && iter1.GetMapIter() == iter2;
 | 
						return !iter1.ListValid() && iter1.GetMapIter() == iter2;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -268,8 +269,8 @@ bool operator==(const Tmap_iter2 &iter2, const MultiMapIterator<Tmap_iter1, Tlis
 | 
				
			|||||||
 * @param iter1 MultiMap iterator.
 | 
					 * @param iter1 MultiMap iterator.
 | 
				
			||||||
 * @return If iter1 doesn't point to the begin of the list pointed to by iter2.
 | 
					 * @return If iter1 doesn't point to the begin of the list pointed to by iter2.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
template<class Tmap_iter1, class Tlist_iter1, class Tmap_iter2, class Tkey, class Tvalue, class Tcompare >
 | 
					template<class Tmap_iter1, class Tlist_iter1, class Tmap_iter2, class Tkey, class Tvalue, class Tcontainer, class Tcompare >
 | 
				
			||||||
bool operator!=(const Tmap_iter2 &iter2, const MultiMapIterator<Tmap_iter1, Tlist_iter1, Tkey, Tvalue, Tcompare> &iter1)
 | 
					bool operator!=(const Tmap_iter2 &iter2, const MultiMapIterator<Tmap_iter1, Tlist_iter1, Tkey, Tvalue, Tcontainer, Tcompare> &iter1)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	return iter1.ListValid() || iter1.GetMapIter() != iter2;
 | 
						return iter1.ListValid() || iter1.GetMapIter() != iter2;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -282,10 +283,10 @@ bool operator!=(const Tmap_iter2 &iter2, const MultiMapIterator<Tmap_iter1, Tlis
 | 
				
			|||||||
 * STL-compatible members are named in STL style, all others are named in OpenTTD
 | 
					 * STL-compatible members are named in STL style, all others are named in OpenTTD
 | 
				
			||||||
 * style.
 | 
					 * style.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
template<typename Tkey, typename Tvalue, typename Tcompare = std::less<Tkey> >
 | 
					template<typename Tkey, typename Tvalue, typename Tcontainer = std::list<Tvalue>, typename Tcompare = std::less<Tkey> >
 | 
				
			||||||
class MultiMap : public std::map<Tkey, std::list<Tvalue>, Tcompare > {
 | 
					class MultiMap : public std::map<Tkey, Tcontainer, Tcompare > {
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
	typedef typename std::list<Tvalue> List;
 | 
						typedef Tcontainer List;
 | 
				
			||||||
	typedef typename List::iterator ListIterator;
 | 
						typedef typename List::iterator ListIterator;
 | 
				
			||||||
	typedef typename List::const_iterator ConstListIterator;
 | 
						typedef typename List::const_iterator ConstListIterator;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -293,8 +294,8 @@ public:
 | 
				
			|||||||
	typedef typename Map::iterator MapIterator;
 | 
						typedef typename Map::iterator MapIterator;
 | 
				
			||||||
	typedef typename Map::const_iterator ConstMapIterator;
 | 
						typedef typename Map::const_iterator ConstMapIterator;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	typedef MultiMapIterator<MapIterator, ListIterator, Tkey, Tvalue, Tcompare> iterator;
 | 
						typedef MultiMapIterator<MapIterator, ListIterator, Tkey, Tvalue, Tcontainer, Tcompare> iterator;
 | 
				
			||||||
	typedef MultiMapIterator<ConstMapIterator, ConstListIterator, Tkey, const Tvalue, Tcompare> const_iterator;
 | 
						typedef MultiMapIterator<ConstMapIterator, ConstListIterator, Tkey, const Tvalue, Tcontainer, Tcompare> const_iterator;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Erase the value pointed to by an iterator. The iterator may be invalid afterwards.
 | 
						 * Erase the value pointed to by an iterator. The iterator may be invalid afterwards.
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										12
									
								
								src/stdafx.h
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								src/stdafx.h
									
									
									
									
									
								
							@@ -143,7 +143,7 @@
 | 
				
			|||||||
#endif /* PSP */
 | 
					#endif /* PSP */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Stuff for GCC */
 | 
					/* Stuff for GCC */
 | 
				
			||||||
#if defined(__GNUC__)
 | 
					#if defined(__GNUC__) || defined(__clang__)
 | 
				
			||||||
	#define NORETURN __attribute__ ((noreturn))
 | 
						#define NORETURN __attribute__ ((noreturn))
 | 
				
			||||||
	#define CDECL
 | 
						#define CDECL
 | 
				
			||||||
	#define __int64 long long
 | 
						#define __int64 long long
 | 
				
			||||||
@@ -151,12 +151,8 @@
 | 
				
			|||||||
	/* Warn about functions using 'printf' format syntax. First argument determines which parameter
 | 
						/* Warn about functions using 'printf' format syntax. First argument determines which parameter
 | 
				
			||||||
	 * is the format string, second argument is start of values passed to printf. */
 | 
						 * is the format string, second argument is start of values passed to printf. */
 | 
				
			||||||
	#define WARN_FORMAT(string, args) __attribute__ ((format (printf, string, args)))
 | 
						#define WARN_FORMAT(string, args) __attribute__ ((format (printf, string, args)))
 | 
				
			||||||
	#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7)
 | 
					 | 
				
			||||||
	#define FINAL final
 | 
						#define FINAL final
 | 
				
			||||||
	#else
 | 
					#endif /* __GNUC__ || __clang__ */
 | 
				
			||||||
		#define FINAL
 | 
					 | 
				
			||||||
	#endif
 | 
					 | 
				
			||||||
#endif /* __GNUC__ */
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if defined(__WATCOMC__)
 | 
					#if defined(__WATCOMC__)
 | 
				
			||||||
	#define NORETURN
 | 
						#define NORETURN
 | 
				
			||||||
@@ -431,13 +427,13 @@ assert_compile(SIZE_MAX >= UINT32_MAX);
 | 
				
			|||||||
	#define CloseConnection OTTD_CloseConnection
 | 
						#define CloseConnection OTTD_CloseConnection
 | 
				
			||||||
#endif /* __APPLE__ */
 | 
					#endif /* __APPLE__ */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef __GNUC__
 | 
					#if defined(__GNUC__) || defined(__clang__)
 | 
				
			||||||
#define likely(x)       __builtin_expect(!!(x), 1)
 | 
					#define likely(x)       __builtin_expect(!!(x), 1)
 | 
				
			||||||
#define unlikely(x)     __builtin_expect(!!(x), 0)
 | 
					#define unlikely(x)     __builtin_expect(!!(x), 0)
 | 
				
			||||||
#else
 | 
					#else
 | 
				
			||||||
#define likely(x)       (x)
 | 
					#define likely(x)       (x)
 | 
				
			||||||
#define unlikely(x)     (x)
 | 
					#define unlikely(x)     (x)
 | 
				
			||||||
#endif
 | 
					#endif /* __GNUC__ || __clang__ */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void NORETURN CDECL usererror(const char *str, ...) WARN_FORMAT(1, 2);
 | 
					void NORETURN CDECL usererror(const char *str, ...) WARN_FORMAT(1, 2);
 | 
				
			||||||
void NORETURN CDECL error(const char *str, ...) WARN_FORMAT(1, 2);
 | 
					void NORETURN CDECL error(const char *str, ...) WARN_FORMAT(1, 2);
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user