- Updated preprocessor directives to utilize Standard_CPP17_OR_HIGHER instead of direct __cplusplus checks.
- Removed unnecessary preprocessor checks for C++17 in TCollection_AsciiString implementation and tests.
- Enhanced code readability and maintainability by centralizing C++ version checks.
// Tests for std::string_view API
// ========================================
-#if defined(__cplusplus) && __cplusplus >= 201703L
TEST(TCollection_AsciiStringTest, StringView_Constructor)
{
std::string_view aView("Hello World");
aString.Insert(2, aView);
EXPECT_STREQ("HelloWorld", aString.ToCString());
}
-#endif
// ========================================
// Tests for Move semantics
#endif
#endif
+//! @def Standard_CPP17_OR_HIGHER
+//! Macro to check if C++ standard version is C++17 or higher.
+//!
+//! Expands to 1 if C++17 or higher is available, 0 otherwise.
+//! Uses _MSVC_LANG for MSVC (available since VS 2017.3) which correctly
+//! reports the language standard regardless of /Zc:__cplusplus flag.
+//! For other compilers or as fallback, uses __cplusplus standard macro.
+#if defined(_MSC_VER) && defined(_MSVC_LANG) && _MSVC_LANG >= 201703L
+ // MSVC: _MSVC_LANG correctly reports language standard (available since VS 2017.3)
+ #define Standard_CPP17_OR_HIGHER 1
+#elif defined(__cplusplus) && __cplusplus >= 201703L
+ // Standard __cplusplus check for GCC, Clang, and MSVC when _MSVC_LANG is not available
+ #define Standard_CPP17_OR_HIGHER 1
+#else
+ #define Standard_CPP17_OR_HIGHER 0
+#endif
+
#endif
#include <Standard_IStream.hxx>
#include <Standard_Macro.hxx>
-#if __cplusplus >= 201703L
+#if Standard_CPP17_OR_HIGHER
#include <string_view>
#endif
//! Initializes a AsciiString to an empty AsciiString.
Standard_EXPORT TCollection_AsciiString();
-#if __cplusplus >= 201703L
+#if Standard_CPP17_OR_HIGHER
//! Initializes a AsciiString with a string_view.
//! @param[in] theStringView the string view to initialize from
explicit inline TCollection_AsciiString(const std::string_view& theStringView);
void operator+=(const Standard_CString theCString) { AssignCat(theCString); }
-#if __cplusplus >= 201703L
+#if Standard_CPP17_OR_HIGHER
//! Appends string view to this ASCII string. This is an unary operator.
//! @param[in] theStringView the string view to append
inline void AssignCat(const std::string_view& theStringView);
inline TCollection_AsciiString operator+(const Standard_CString theCString) const;
-#if __cplusplus >= 201703L
+#if Standard_CPP17_OR_HIGHER
//! Appends string view to this ASCII string.
//! @param[in] theStringView the string view to append
//! @return new string with string view appended
void operator=(const Standard_CString theCString) { Copy(theCString); }
-#if __cplusplus >= 201703L
+#if Standard_CPP17_OR_HIGHER
//! Copy string view to this ASCII string.
//! Used as operator =
//! @param[in] theStringView the string view to copy from
const Standard_Integer theFromIndex,
const Standard_Integer theToIndex) const;
-#if __cplusplus >= 201703L
+#if Standard_CPP17_OR_HIGHER
//! Returns the index of the first character of this string that is present in string_view.
//! @param[in] theSet the string view of characters to search for
//! @param[in] theFromIndex the starting index for search
const Standard_Integer theFromIndex,
const Standard_Integer theToIndex) const;
-#if __cplusplus >= 201703L
+#if Standard_CPP17_OR_HIGHER
//! Returns the index of the first character of this string that is not present in string_view.
//! @param[in] theSet the string view of characters to check against
//! @param[in] theFromIndex the starting index for search
//! @param[in] theCString the C string to insert
inline void Insert(const Standard_Integer theWhere, const Standard_CString theCString);
-#if __cplusplus >= 201703L
+#if Standard_CPP17_OR_HIGHER
//! Inserts a string_view at position theWhere.
//! @param[in] theWhere position to insert at
//! @param[in] theStringView the string view to insert
//! @param[in] theCString the C string to insert
inline void InsertAfter(const Standard_Integer theIndex, const Standard_CString theCString);
-#if __cplusplus >= 201703L
+#if Standard_CPP17_OR_HIGHER
//! Inserts a string_view after a specific index in this string.
//! Raises an exception if index is out of bounds.
//! @param[in] theIndex the index to insert after
//! @param[in] theCString the C string to insert
inline void InsertBefore(const Standard_Integer theIndex, const Standard_CString theCString);
-#if __cplusplus >= 201703L
+#if Standard_CPP17_OR_HIGHER
//! Inserts a string_view before a specific index in this string.
//! Raises an exception if index is out of bounds.
//! @param[in] theIndex the index to insert before
inline Standard_Boolean operator==(const Standard_CString theCString) const;
-#if __cplusplus >= 201703L
+#if Standard_CPP17_OR_HIGHER
//! Returns true if the characters in this ASCII string
//! are identical to the characters in string_view.
//! @param[in] theStringView the string view to compare with
inline Standard_Boolean operator!=(const Standard_CString theCString) const;
-#if __cplusplus >= 201703L
+#if Standard_CPP17_OR_HIGHER
//! Returns true if there are differences between the
//! characters in this ASCII string and string_view.
//! @param[in] theStringView the string view to compare with
Standard_Boolean operator<(const Standard_CString theCString) const { return IsLess(theCString); }
-#if __cplusplus >= 201703L
+#if Standard_CPP17_OR_HIGHER
//! Returns TRUE if this ASCII string is lexicographically less than theStringView.
//! @param[in] theStringView the string view to compare with
//! @return true if this string is lexicographically less than theStringView
inline Standard_Boolean operator>(const Standard_CString theCString) const;
-#if __cplusplus >= 201703L
+#if Standard_CPP17_OR_HIGHER
//! Returns TRUE if this ASCII string is lexicographically greater than theStringView.
//! @param[in] theStringView the string view to compare with
//! @return true if this string is lexicographically greater than theStringView
//! @return true if this string starts with theCString
inline Standard_Boolean StartsWith(const Standard_CString theCString) const;
-#if __cplusplus >= 201703L
+#if Standard_CPP17_OR_HIGHER
//! Determines whether the beginning of this string instance matches the specified string_view.
//! @param[in] theStartString the string view to check for at the beginning
//! @return true if this string starts with theStartString
//! @return true if this string ends with theEndString
inline Standard_Boolean EndsWith(const TCollection_AsciiString& theEndString) const;
-#if __cplusplus >= 201703L
+#if Standard_CPP17_OR_HIGHER
//! Determines whether the end of this string instance matches the specified string_view.
//! @param[in] theEndString the string view to check for at the end
//! @return true if this string ends with theEndString
//! @return the position of first match, or -1 if not found
inline Standard_Integer Search(const Standard_CString theCString) const;
-#if __cplusplus >= 201703L
+#if Standard_CPP17_OR_HIGHER
//! Searches a string_view in this string from the beginning
//! and returns position of first item matching.
//! It returns -1 if not found.
//! @return the position of first match from end, or -1 if not found
inline Standard_Integer SearchFromEnd(const Standard_CString theCString) const;
-#if __cplusplus >= 201703L
+#if Standard_CPP17_OR_HIGHER
//! Searches a string_view in this string from the end
//! and returns position of first item matching.
//! It returns -1 if not found.
//! @param[in] theCString the C string to replace with
inline void SetValue(const Standard_Integer theWhere, const Standard_CString theCString);
-#if __cplusplus >= 201703L
+#if Standard_CPP17_OR_HIGHER
//! Replaces a part of this ASCII string with a string_view.
//! @param[in] theWhere position to start replacement
//! @param[in] theStringView the string view to replace with
//! @return the C string representation
Standard_CString ToCString() const { return myString; }
-#if __cplusplus >= 201703L
+#if Standard_CPP17_OR_HIGHER
//! Returns string_view for this AsciiString.
//! This provides a lightweight, non-owning view of the string data.
//! @return the string_view representation
static Standard_Boolean IsEqual(const TCollection_AsciiString& string1,
const Standard_CString string2);
-#if __cplusplus >= 201703L
+#if Standard_CPP17_OR_HIGHER
//! Returns True when the ASCII string and string_view are the same.
//! (Just for HashCode for AsciiString)
//! @param[in] theString1 first string to compare
const TCollection_AsciiString& theString2,
const Standard_Boolean theIsCaseSensitive);
-#if __cplusplus >= 201703L
+#if Standard_CPP17_OR_HIGHER
//! Returns True if the string and string_view contain same characters.
//! @param[in] theString1 first string to compare
//! @param[in] theStringView second string view to compare
const Standard_CString theCString2,
const Standard_Boolean theIsCaseSensitive);
-#if __cplusplus >= 201703L
+#if Standard_CPP17_OR_HIGHER
//! Returns True if the two string_views contain same characters.
//! @param[in] theStringView1 first string view to compare
//! @param[in] theStringView2 second string view to compare
//=================================================================================================
-#if __cplusplus >= 201703L
+#if Standard_CPP17_OR_HIGHER
inline void TCollection_AsciiString::AssignCat(const std::string_view& theStringView)
{
if (!theStringView.empty())
//=================================================================================================
-#if __cplusplus >= 201703L
+#if Standard_CPP17_OR_HIGHER
inline TCollection_AsciiString TCollection_AsciiString::Cat(
const std::string_view& theStringView) const
{
//=================================================================================================
-#if __cplusplus >= 201703L
+#if Standard_CPP17_OR_HIGHER
inline void TCollection_AsciiString::Copy(const std::string_view& theStringView)
{
Copy(theStringView.data(), static_cast<Standard_Integer>(theStringView.size()));
//=================================================================================================
-#if __cplusplus >= 201703L
+#if Standard_CPP17_OR_HIGHER
inline void TCollection_AsciiString::Insert(const Standard_Integer theWhere,
const std::string_view& theStringView)
{
//=================================================================================================
-#if __cplusplus >= 201703L
+#if Standard_CPP17_OR_HIGHER
inline void TCollection_AsciiString::InsertAfter(const Standard_Integer theIndex,
const std::string_view& theStringView)
{
//=================================================================================================
-#if __cplusplus >= 201703L
+#if Standard_CPP17_OR_HIGHER
inline void TCollection_AsciiString::InsertBefore(const Standard_Integer theIndex,
const std::string_view& theStringView)
{
//=================================================================================================
-#if __cplusplus >= 201703L
+#if Standard_CPP17_OR_HIGHER
inline Standard_Boolean TCollection_AsciiString::IsEqual(
const std::string_view& theStringView) const
{
//=================================================================================================
-#if __cplusplus >= 201703L
+#if Standard_CPP17_OR_HIGHER
inline Standard_Boolean TCollection_AsciiString::IsDifferent(
const std::string_view& theStringView) const
{
//=================================================================================================
-#if __cplusplus >= 201703L
+#if Standard_CPP17_OR_HIGHER
inline Standard_Boolean TCollection_AsciiString::IsLess(const std::string_view& theStringView) const
{
return IsLess(theStringView.data(), static_cast<Standard_Integer>(theStringView.size()));
//=================================================================================================
-#if __cplusplus >= 201703L
+#if Standard_CPP17_OR_HIGHER
inline Standard_Boolean TCollection_AsciiString::IsGreater(
const std::string_view& theStringView) const
{
//=================================================================================================
-#if __cplusplus >= 201703L
+#if Standard_CPP17_OR_HIGHER
inline Standard_Boolean TCollection_AsciiString::StartsWith(
const std::string_view& theStartString) const
{
//=================================================================================================
-#if __cplusplus >= 201703L
+#if Standard_CPP17_OR_HIGHER
inline Standard_Boolean TCollection_AsciiString::EndsWith(
const std::string_view& theEndString) const
{
//=================================================================================================
-#if __cplusplus >= 201703L
+#if Standard_CPP17_OR_HIGHER
inline Standard_Integer TCollection_AsciiString::Search(const std::string_view& theWhat) const
{
return Search(theWhat.data(), static_cast<Standard_Integer>(theWhat.size()));
//=================================================================================================
-#if __cplusplus >= 201703L
+#if Standard_CPP17_OR_HIGHER
inline Standard_Integer TCollection_AsciiString::SearchFromEnd(
const std::string_view& theWhat) const
{
//=================================================================================================
-#if __cplusplus >= 201703L
+#if Standard_CPP17_OR_HIGHER
inline void TCollection_AsciiString::SetValue(const Standard_Integer theWhere,
const std::string_view& theStringView)
{
//=================================================================================================
-#if __cplusplus >= 201703L
+#if Standard_CPP17_OR_HIGHER
inline Standard_Boolean TCollection_AsciiString::IsEqual(const TCollection_AsciiString& theString1,
const std::string_view& theStringView)
{
//=================================================================================================
-#if __cplusplus >= 201703L
+#if Standard_CPP17_OR_HIGHER
inline Standard_Boolean TCollection_AsciiString::IsEqual(const std::string_view& theStringView,
const TCollection_AsciiString& theString2)
{
//=================================================================================================
-#if __cplusplus >= 201703L
+#if Standard_CPP17_OR_HIGHER
inline Standard_Boolean TCollection_AsciiString::IsSameString(
const TCollection_AsciiString& theString1,
const std::string_view& theStringView,
//=================================================================================================
-#if __cplusplus >= 201703L
+#if Standard_CPP17_OR_HIGHER
inline Standard_Boolean TCollection_AsciiString::IsSameString(
const std::string_view& theStringView,
const TCollection_AsciiString& theString2,
//=================================================================================================
-#if __cplusplus >= 201703L
+#if Standard_CPP17_OR_HIGHER
inline Standard_Boolean TCollection_AsciiString::IsSameString(
const std::string_view& theStringView1,
const std::string_view& theStringView2,
//=================================================================================================
-#if __cplusplus >= 201703L
+#if Standard_CPP17_OR_HIGHER
inline Standard_Integer TCollection_AsciiString::FirstLocationInSet(
const std::string_view& theSet,
const Standard_Integer theFromIndex,
//=================================================================================================
-#if __cplusplus >= 201703L
+#if Standard_CPP17_OR_HIGHER
inline Standard_Integer TCollection_AsciiString::FirstLocationNotInSet(
const std::string_view& theSet,
const Standard_Integer theFromIndex,
//=================================================================================================
-#if __cplusplus >= 201703L
+#if Standard_CPP17_OR_HIGHER
inline TCollection_AsciiString TCollection_AsciiString::operator+(
const std::string_view& theStringView) const
{
//=================================================================================================
-#if __cplusplus >= 201703L
+#if Standard_CPP17_OR_HIGHER
inline Standard_Boolean TCollection_AsciiString::operator==(
const std::string_view& theStringView) const
{
//=================================================================================================
-#if __cplusplus >= 201703L
+#if Standard_CPP17_OR_HIGHER
inline Standard_Boolean TCollection_AsciiString::operator!=(
const std::string_view& theStringView) const
{
//=================================================================================================
-#if __cplusplus >= 201703L
+#if Standard_CPP17_OR_HIGHER
inline Standard_Boolean TCollection_AsciiString::operator<(
const std::string_view& theStringView) const
{
//=================================================================================================
-#if __cplusplus >= 201703L
+#if Standard_CPP17_OR_HIGHER
inline Standard_Boolean TCollection_AsciiString::operator>(
const std::string_view& theStringView) const
{
//=================================================================================================
-#if __cplusplus >= 201703L
+#if Standard_CPP17_OR_HIGHER
inline TCollection_AsciiString::TCollection_AsciiString(const std::string_view& theStringView)
: TCollection_AsciiString(theStringView.data(),
static_cast<Standard_Integer>(theStringView.size()))