ENH: Added operator!= for stl string and char* when the system does not provide one.

This commit is contained in:
Brad King 2005-03-29 10:10:25 -05:00
parent 22f6d68be3
commit 65f1e3e1d8
4 changed files with 47 additions and 10 deletions

View File

@ -175,6 +175,9 @@ ELSE(KWSYS_IOS_USE_SSTREAM)
ENDIF(KWSYS_IOS_USE_STRSTREAM_H)
ENDIF(KWSYS_IOS_USE_SSTREAM)
KWSYS_PLATFORM_CXX_TEST(KWSYS_STL_STRING_HAVE_NEQ_CHAR
"Checking whether stl string has operator!= for char*" DIRECT)
IF(KWSYS_IOS_USE_ANSI)
# ANSI streams always have string operators.
SET(KWSYS_STL_STRING_HAVE_OSTREAM 1)

View File

@ -41,6 +41,9 @@
/* Whether the STL string has operator>> for istream. */
#define @KWSYS_NAMESPACE@_STL_STRING_HAVE_ISTREAM @KWSYS_STL_STRING_HAVE_ISTREAM@
/* Whether the STL string has operator!= for char*. */
#define @KWSYS_NAMESPACE@_STL_STRING_HAVE_NEQ_CHAR @KWSYS_STL_STRING_HAVE_NEQ_CHAR@
/* Define the stl namespace macro. */
#if @KWSYS_NAMESPACE@_STL_HAVE_STD
# define @KWSYS_NAMESPACE@_stl std
@ -80,6 +83,7 @@
# define KWSYS_STAT_HAS_ST_MTIM @KWSYS_NAMESPACE@_STAT_HAS_ST_MTIM
# define KWSYS_STL_STRING_HAVE_OSTREAM @KWSYS_NAMESPACE@_STL_STRING_HAVE_OSTREAM
# define KWSYS_STL_STRING_HAVE_ISTREAM @KWSYS_NAMESPACE@_STL_STRING_HAVE_ISTREAM
# define KWSYS_STL_STRING_HAVE_NEQ_CHAR @KWSYS_NAMESPACE@_STL_STRING_HAVE_NEQ_CHAR
#endif
#endif

View File

@ -54,6 +54,17 @@ void f(istream& is, kwsys_stl::string& s) { is >> s; }
int main() { return 0; }
#endif
#ifdef TEST_KWSYS_STL_STRING_HAVE_NEQ_CHAR
# if KWSYS_STL_HAVE_STD
# define kwsys_stl std
# else
# define kwsys_stl
# endif
# include <string>
bool f(const kwsys_stl::string& s) { return s != ""; }
int main() { return 0; }
#endif
#ifdef TEST_KWSYS_STAT_HAS_ST_MTIM
#include <sys/types.h>
#include <sys/stat.h>

View File

@ -90,3 +90,22 @@ operator<<(@KWSYS_NAMESPACE@_ios::ostream& os,
return os << s.c_str();
}
#endif
// Provide the operator!= for the stl string and char* if it is not
// provided by the system or another copy of kwsys. Allow user code
// to block this definition by defining the macro
// @KWSYS_NAMESPACE@_STL_STRING_NO_NEQ_CHAR
// to avoid conflicts with other libraries.
#if !@KWSYS_NAMESPACE@_STL_STRING_HAVE_NEQ_CHAR && \
!defined(@KWSYS_NAMESPACE@_STL_STRING_NO_NEQ_CHAR) && \
!defined(KWSYS_STL_STRING_NEQ_CHAR_DEFINED)
# define KWSYS_STL_STRING_NEQ_CHAR_DEFINED
inline bool operator!=(@KWSYS_NAMESPACE@_stl::string const& s, const char* c)
{
return !(s == c);
}
inline bool operator!=(const char* c, @KWSYS_NAMESPACE@_stl::string const& s)
{
return !(s == c);
}
#endif