[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [4948] Support outmoded compilers
From: |
Greg Chicares |
Subject: |
[lmi-commits] [4948] Support outmoded compilers |
Date: |
Fri, 14 May 2010 00:39:16 +0000 |
Revision: 4948
http://svn.sv.gnu.org/viewvc/?view=rev&root=lmi&revision=4948
Author: chicares
Date: 2010-05-14 00:39:16 +0000 (Fri, 14 May 2010)
Log Message:
-----------
Support outmoded compilers
Modified Paths:
--------------
lmi/trunk/ChangeLog
lmi/trunk/contains.hpp
lmi/trunk/contains_test.cpp
Modified: lmi/trunk/ChangeLog
===================================================================
--- lmi/trunk/ChangeLog 2010-05-13 22:40:50 UTC (rev 4947)
+++ lmi/trunk/ChangeLog 2010-05-14 00:39:16 UTC (rev 4948)
@@ -25739,3 +25739,9 @@
contains_test.cpp
Improve discrimination among containers.
+20100514T0039Z <address@hidden> [706]
+
+ contains.hpp
+ contains_test.cpp
+Support outmoded compilers.
+
Modified: lmi/trunk/contains.hpp
===================================================================
--- lmi/trunk/contains.hpp 2010-05-13 22:40:50 UTC (rev 4947)
+++ lmi/trunk/contains.hpp 2010-05-14 00:39:16 UTC (rev 4948)
@@ -32,9 +32,16 @@
#if defined __BORLANDC__ || defined __COMO_VERSION__ && __COMO_VERSION__ <=
4303
# define LMI_NO_SFINAE
+# include <deque>
+# include <list>
+# include <map>
+# include <set>
+# include <string>
+# include <vector>
#endif // defined __BORLANDC__ || defined __COMO_VERSION__ && __COMO_VERSION__
<= 4303
#if !defined LMI_NO_SFINAE
+
/// Determine whether a class has a find() member.
///
/// See:
@@ -63,7 +70,6 @@
static bool const value = sizeof(yea_t) == sizeof deduce((Derived*)(0));
};
-#endif // !defined LMI_NO_SFINAE
/// Ascertain whether a "container" includes a given element.
///
@@ -128,5 +134,56 @@
return t.end() != t.find(element);
}
+#else // defined LMI_NO_SFINAE
+
+// Strings. Only std::string is supported here: compilers that can't
+// handle SFINAE might not provide std::basic_string either.
+
+bool contains(std::string const& t, std::string const& element)
+{
+ return std::string::npos != t.find(element);
+}
+
+bool contains(std::string const& t, char const* element)
+{
+ return std::string::npos != t.find(element);
+}
+
+// Associative containers.
+
+template<typename K, typename T>
+bool contains(std::map<K,T> const& t, typename std::map<K,T>::key_type const&
element)
+{
+ return t.end() != t.find(element);
+}
+
+template<typename T>
+bool contains(std::set<T> const& t, typename std::set<T>::key_type const&
element)
+{
+ return t.end() != t.find(element);
+}
+
+// Sequences.
+
+template<typename T>
+bool contains(std::deque<T> const& t, T const& element)
+{
+ return t.end() != std::find(t.begin(), t.end(), element);
+}
+
+template<typename T>
+bool contains(std::list<T> const& t, T const& element)
+{
+ return t.end() != std::find(t.begin(), t.end(), element);
+}
+
+template<typename T>
+bool contains(std::vector<T> const& t, T const& element)
+{
+ return t.end() != std::find(t.begin(), t.end(), element);
+}
+
+#endif // defined LMI_NO_SFINAE
+
#endif // contains_hpp
Modified: lmi/trunk/contains_test.cpp
===================================================================
--- lmi/trunk/contains_test.cpp 2010-05-13 22:40:50 UTC (rev 4947)
+++ lmi/trunk/contains_test.cpp 2010-05-14 00:39:16 UTC (rev 4948)
@@ -69,8 +69,8 @@
std::string const x("lorem ipsum");
std::string const y[] = {"O Sibili", "si ergo", "fortibus es", "in ero"};
std::pair<std::string,std::string> const z[] =
- {std::make_pair<std::string,std::string>("O Nobili", "demis trux")
- ,std::make_pair<std::string,std::string>("uatis inem", "causendux")
+ {std::pair<std::string,std::string>("O Nobili", "demis trux")
+ ,std::pair<std::string,std::string>("uatis inem", "causendux")
};
// Strings.
@@ -82,12 +82,20 @@
// Associative containers.
+#if !defined __BORLANDC__
std::map<std::string,std::string> const m(z, z + lmi_array_size(z));
- BOOST_TEST( contains(m, "uatis inem"));
+#else // defined __BORLANDC__
+ std::map<std::string,std::string> const m(z, z + 2);
+#endif // defined __BORLANDC__
+ BOOST_TEST( contains(m, "uatis inem" ));
BOOST_TEST(!contains(m, "cows and ducks"));
+#if !defined __BORLANDC__
std::set<std::string> const s(y, y + lmi_array_size(y));
- BOOST_TEST( contains(s, "si ergo"));
+#else // defined __BORLANDC__
+ std::set<std::string> const s(y, y + 4);
+#endif // defined __BORLANDC__
+ BOOST_TEST( contains(s, "si ergo" ));
BOOST_TEST(!contains(s, "fortibus"));
// Sequences.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [lmi-commits] [4948] Support outmoded compilers,
Greg Chicares <=