This implements additions from sections 4.3, 4.4, 4.5 of P3016R6.
libstdc++-v3/ChangeLog:
* include/bits/version.def (valarray): Define.
* include/bits/version.h: Regenerate.
* include/std/valarray: (__cpp_lib_valarray): Define.
(valarray::begin, valarray::end, valarray::iterator)
(valarray::const_iterator) [__glibcxx_valarray >= 202511L]: Define.
(std::begin(valarray<_Tp>&), std::begin(const valarray<_Tp>&))
(std::end(valarray<_Tp>&), std::end(const valarray<_Tp>&)): Define
only if __glibcxx_valarray < 202511L (i.e. not defined).
* include/bits/range_access.h (std::valarray)
(std::begin(valarray<_Tp>&), std::begin(const valarray<_Tp>&))
(std::end(valarray<_Tp>&), std::end(const valarray<_Tp>&)): Forward
declare only if __glibcxx_valarray < 202511L (i.e. not defined).
* testsuite/26_numerics/valarray/range_access3.cc: New test.
Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Reviewed-by: Nathan Myers <ncm@cantrip.org>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
#if __cplusplus >= 201402L
+#if __glibcxx_valarray < 202511L
template<typename _Tp> class valarray;
// These overloads must be declared for cbegin and cend to use them.
template<typename _Tp> _Tp* begin(valarray<_Tp>&) noexcept;
template<typename _Tp> const _Tp* begin(const valarray<_Tp>&) noexcept;
template<typename _Tp> _Tp* end(valarray<_Tp>&) noexcept;
template<typename _Tp> const _Tp* end(const valarray<_Tp>&) noexcept;
+#endif
/**
* @brief Return an iterator pointing to the first element of
};
};
+ftms = {
+ name = valarray;
+ values = {
+ v = 202511;
+ cxxmin = 26;
+ };
+};
+
// Standard test specifications.
stds[97] = ">= 199711L";
stds[03] = ">= 199711L";
#endif /* !defined(__cpp_lib_initializer_list) */
#undef __glibcxx_want_initializer_list
+#if !defined(__cpp_lib_valarray)
+# if (__cplusplus > 202302L)
+# define __glibcxx_valarray 202511L
+# if defined(__glibcxx_want_all) || defined(__glibcxx_want_valarray)
+# define __cpp_lib_valarray 202511L
+# endif
+# endif
+#endif /* !defined(__cpp_lib_valarray) */
+#undef __glibcxx_want_valarray
+
#undef __glibcxx_want_all
#include <bits/range_access.h>
#endif
+#define __glibcxx_want_valarray
+#include <bits/version.h>
+
namespace std _GLIBCXX_VISIBILITY(default)
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION
};
public:
typedef _Tp value_type;
+#if __glibcxx_valarray >= 202511L
+ typedef _Tp* iterator;
+ typedef const _Tp* const_iterator;
+#endif
// _lib.valarray.cons_ construct/destroy:
/// Construct an empty array.
*/
void resize(size_t __size, _Tp __c = _Tp());
+#if __glibcxx_valarray >= 202511L
+ /**
+ * @brief Return an iterator pointing to the first element of
+ * the valarray.
+ */
+ [[nodiscard]]
+ iterator
+ begin() noexcept
+ { return _M_data; }
+
+ [[nodiscard]]
+ const_iterator
+ begin() const noexcept
+ { return _M_data; }
+
+ /**
+ * @brief Return an iterator pointing to one past the last element of
+ * the valarray.
+ */
+ [[nodiscard]]
+ iterator
+ end() noexcept
+ { return _M_data + _M_size; }
+
+ [[nodiscard]]
+ const_iterator
+ end() const noexcept
+ { return _M_data + _M_size; }
+#endif
+
private:
size_t _M_size;
_Tp* __restrict__ _M_data;
#undef _DEFINE_BINARY_OPERATOR
/// @endcond
-#if __cplusplus >= 201103L
+#if (__cplusplus >= 201103L) && (__glibcxx_valarray < 202511L)
/**
* @brief Return an iterator pointing to the first element of
* the valarray.
else
return nullptr;
}
-#endif // C++11
+#endif // C++11 to C++23
/// @} group numeric_arrays
--- /dev/null
+// { dg-do run { target c++26 } }
+
+#include <valarray>
+#include <testsuite_hooks.h>
+
+#ifndef __cpp_lib_valarray
+# error "Feature-test macro for text_encoding missing in <initializer_list>"
+#elif __cpp_lib_valarray != 202511L
+# error "Feature-test macro for text_encoding has wrong value in <initializer_list>"
+#endif
+
+void
+test01()
+{
+ std::valarray<double> va(3);
+ va[0] = 1.0; va[1] = 2.0; va[2] = 3.0;
+
+ typename std::valarray<double>::iterator it = va.begin();
+ VERIFY( it != va.end() );
+ VERIFY( *it++ == 1.0 );
+ VERIFY( *it++ == 2.0 );
+ VERIFY( *it++ == 3.0 );
+ VERIFY( it == va.end() );
+
+ const std::valarray<double>& cva = va;
+ typename std::valarray<double>::const_iterator cit = cva.begin();
+ VERIFY( cit != va.end() );
+ VERIFY( *cit++ == 1.0 );
+ VERIFY( *cit++ == 2.0 );
+ VERIFY( *cit++ == 3.0 );
+ VERIFY( cit == cva.end() );
+}
+
+void
+test02()
+{
+ std::valarray<double> va;
+ VERIFY( va.begin() == va.end() );
+ const std::valarray<double>& cva = va;
+ VERIFY( cva.begin() == cva.end() );
+}
+
+int main()
+{
+ test01();
+ test02();
+}