6 Commits 4e074a57d3 ... 35a7f828e7

Author SHA1 Message Date
  __vic 35a7f828e7 readonly_cstring: duplicated code removed 2 months ago
  __vic 46f0cbb4c4 Protection from isascii() macro added 2 months ago
  __vic 0a5d89abd5 Logical operator traits added 2 months ago
  __vic 27889effe4 Parens for __VIC_STD_MOVE(v) parameter 6 months ago
  __vic 1691f6baba __VIC_SWAP_HEADER fix 6 months ago
  __vic 7b2a82cbf5 __VIC_INLINE_CONSTEXPR_VAR added 6 months ago

+ 13 - 0
ChangeLog

@@ -4,6 +4,19 @@ Legend:
     * Changes
     ! Important
 
+2024-02-27  __vic
+    * ascii.h: protection from isascii() macro
+    * readonly_cstring: duplicated code removed
+
+2024-02-16  __vic
+    * type_traits.h:
+        + conditional
+        + conjunction, disjunction, negation
+
+2023-10-20  __vic
+    + __VIC_INLINE_CONSTEXPR_VAR
+    - __VIC_SWAP_HEADER definition was invalid
+
 2023-10-06  __vic
     + C++23 mode support
     * C++17 is used by default

+ 4 - 2
doc/en/readonly_cstring.h.xml

@@ -22,8 +22,9 @@ public:
 
     readonly_cstring &operator=(const char *str);
     readonly_cstring &operator=(const readonly_cstring &str);
-    readonly_cstring &assign(const char *begin, const char *end);
+    readonly_cstring &assign(const char *str);
     readonly_cstring &assign(const char *chars, size_t n);
+    readonly_cstring &assign(const char *begin, const char *end);
 
     bool empty() const;
     const char *c_str() const;
@@ -103,14 +104,15 @@ for such purposes.</p>
 </synopsis>
 
 <synopsis>
-<prototype>readonly_cstring(const char *begin, const char *end)</prototype>
 <prototype>readonly_cstring(const char *chars, size_t n)</prototype>
+<prototype>readonly_cstring(const char *begin, const char *end)</prototype>
 <p>Creates a string from characters range.</p>
 </synopsis>
 
 <synopsis>
 <prototype>readonly_cstring &amp;operator=(const char *str)</prototype>
 <prototype>readonly_cstring &amp;operator=(const readonly_cstring &amp;str)</prototype>
+<prototype>readonly_cstring &amp;assign(const char *str)</prototype>
 <p>Assigns <tt>str</tt>.</p>
 </synopsis>
 

+ 54 - 0
doc/en/type_traits.h.xml

@@ -103,6 +103,44 @@ types" (see the Standard).</p>
 </chapter>
 
 
+<chapter xml:id="conjunction">
+<title><tt>conjunction</tt> <sign>C++11</sign></title>
+
+<code-block lang="C++"><![CDATA[
+template<class... B> struct conjunction;
+]]></code-block>
+
+<p>A predicate. The logical conjunction of the predicates <tt>B...</tt>.
+False iff one of the <tt>B...</tt> is false.</p>
+
+</chapter>
+
+
+<chapter xml:id="disjunction">
+<title><tt>disjunction</tt> <sign>C++11</sign></title>
+
+<code-block lang="C++"><![CDATA[
+template<class... B> struct disjunction;
+]]></code-block>
+
+<p>A predicate. The logical disjunction of the predicates <tt>B...</tt>.
+True iff one of the <tt>B...</tt> is true.</p>
+
+</chapter>
+
+
+<chapter xml:id="negation">
+<title><tt>negation</tt></title>
+
+<code-block lang="C++"><![CDATA[
+template<class B> struct negation;
+]]></code-block>
+
+<p>A predicate. The logical negation of the predicate <tt>B</tt>.</p>
+
+</chapter>
+
+
 <chapter xml:id="remove_const">
 <title><tt>remove_const</tt></title>
 
@@ -187,6 +225,22 @@ template<class T> using remove_pointer_t = typename remove_pointer<T>::type;
 </chapter>
 
 
+<chapter xml:id="conditional">
+<title><tt>conditional</tt></title>
+
+<code-block lang="C++"><![CDATA[
+template<bool Cond, class Then, class Else> struct conditional;
+
+template<bool Cond, class Then, class Else>
+using conditional_t = typename conditional<Cond, Then, Else>;
+]]></code-block>
+
+<p>A type transformer. Returns <tt>Then</tt> if <tt>Cond == true</tt>.
+<tt>Else</tt> is returned otherwise.</p>
+
+</chapter>
+
+
 <chapter xml:id="enable_if">
 <title><tt>enable_if</tt>, <tt>disable_if</tt></title>
 

+ 4 - 2
doc/ru/readonly_cstring.h.xml

@@ -22,8 +22,9 @@ public:
 
     readonly_cstring &operator=(const char *str);
     readonly_cstring &operator=(const readonly_cstring &str);
-    readonly_cstring &assign(const char *begin, const char *end);
+    readonly_cstring &assign(const char *str);
     readonly_cstring &assign(const char *chars, size_t n);
+    readonly_cstring &assign(const char *begin, const char *end);
 
     bool empty() const;
     const char *c_str() const;
@@ -105,14 +106,15 @@ void swap(readonly_cstring &s1, readonly_cstring &s2) noexcept;
 </synopsis>
 
 <synopsis>
-<prototype>readonly_cstring(const char *begin, const char *end)</prototype>
 <prototype>readonly_cstring(const char *chars, size_t n)</prototype>
+<prototype>readonly_cstring(const char *begin, const char *end)</prototype>
 <p>Создаёт строку из диапазона символов.</p>
 </synopsis>
 
 <synopsis>
 <prototype>readonly_cstring &amp;operator=(const char *str)</prototype>
 <prototype>readonly_cstring &amp;operator=(const readonly_cstring &amp;str)</prototype>
+<prototype>readonly_cstring &amp;assign(const char *str)</prototype>
 <p>Присваивает <tt>str</tt>.</p>
 </synopsis>
 

+ 54 - 0
doc/ru/type_traits.h.xml

@@ -104,6 +104,44 @@ template<class T> struct is_unsigned_integer;
 </chapter>
 
 
+<chapter xml:id="conjunction">
+<title><tt>conjunction</tt> <sign>C++11</sign></title>
+
+<code-block lang="C++"><![CDATA[
+template<class... B> struct conjunction;
+]]></code-block>
+
+<p>Предикат. Конъюнкция предикатов <tt>B...</tt>. Ложен тогда и только тогда,
+когда ложен один из <tt>B...</tt>.</p>
+
+</chapter>
+
+
+<chapter xml:id="disjunction">
+<title><tt>disjunction</tt> <sign>C++11</sign></title>
+
+<code-block lang="C++"><![CDATA[
+template<class... B> struct disjunction;
+]]></code-block>
+
+<p>Предикат. Дизъюнкция предикатов <tt>B...</tt>. Истинен тогда и только тогда,
+когда истинен один из <tt>B...</tt>.</p>
+
+</chapter>
+
+
+<chapter xml:id="negation">
+<title><tt>negation</tt></title>
+
+<code-block lang="C++"><![CDATA[
+template<class B> struct negation;
+]]></code-block>
+
+<p>Предикат. Логическое отрицание предиката <tt>B</tt>.</p>
+
+</chapter>
+
+
 <chapter xml:id="remove_const">
 <title><tt>remove_const</tt></title>
 
@@ -191,6 +229,22 @@ template<class T> using remove_pointer_t = typename remove_pointer<T>::type;
 </chapter>
 
 
+<chapter xml:id="conditional">
+<title><tt>conditional</tt></title>
+
+<code-block lang="C++"><![CDATA[
+template<bool Cond, class Then, class Else> struct conditional;
+
+template<bool Cond, class Then, class Else>
+using conditional_t = typename conditional<Cond, Then, Else>;
+]]></code-block>
+
+<p>Преобразователь типа. Возвращает <tt>Then</tt>, если <tt>Cond == true</tt>.
+В противном случае - <tt>Else</tt>.</p>
+
+</chapter>
+
+
 <chapter xml:id="enable_if">
 <title><tt>enable_if</tt>, <tt>disable_if</tt></title>
 

+ 10 - 4
include/__vic/_cfg.h

@@ -223,7 +223,7 @@
 #endif
 
 //////////////////////////////////////////////////////////////////////////////
-// C++14/C++11/C++98 compatibility macros
+// C++23/C++20/C++17/C++14/C++11/C++98 compatibility macros
 //////////////////////////////////////////////////////////////////////////////
 #if __cplusplus < 201103L && !defined(__VIC_NO_NOEXCEPT_DEF)
 #define noexcept throw()
@@ -239,13 +239,13 @@
 
 #if __cplusplus >= 201103L // C++11
 #   define __VIC_THROWS noexcept(false)
-#   define __VIC_SWAP_HEADER <algorithm>
+#   define __VIC_SWAP_HEADER <utility>
 #   define __VIC_SCOPED_ENUM_UT_BEGIN(name,type) enum class name : type
 #   define __VIC_SCOPED_ENUM_BEGIN(name) enum class name
 #   define __VIC_SCOPED_ENUM_END(name) ; using name##_t = name;
 #else // C++98
 #   define __VIC_THROWS
-#   define __VIC_SWAP_HEADER <utility>
+#   define __VIC_SWAP_HEADER <algorithm>
 #   define __VIC_SCOPED_ENUM_UT_BEGIN(name,type) struct name { enum type_
 #   define __VIC_SCOPED_ENUM_BEGIN(name) struct name { enum type_
 #   define __VIC_SCOPED_ENUM_END(name) ; }; typedef name::type_ name##_t;
@@ -254,7 +254,7 @@
 #if __cpp_rvalue_references
 #   define __VIC_STD_MOVE(v) std::move(v)
 #else
-#   define __VIC_STD_MOVE(v) v
+#   define __VIC_STD_MOVE(v) (v)
 #endif
 
 #if __cpp_constexpr
@@ -273,6 +273,12 @@
 #   define __VIC_CONSTEXPR14 inline
 #endif
 
+#if __cpp_inline_variables
+#   define __VIC_INLINE_CONSTEXPR_VAR inline __VIC_CONSTEXPR_VAR
+#else
+#   define __VIC_INLINE_CONSTEXPR_VAR __VIC_CONSTEXPR_VAR
+#endif
+
 #if __cpp_if_consteval
 #   define __VIC_IF_CONSTEVAL if consteval
 #   define __VIC_IF_NOT_CONSTEVAL if !consteval

+ 1 - 6
include/__vic/ascii.h

@@ -10,11 +10,6 @@
 
 #include<__vic/defs.h>
 
-// FreeBSD 10 defines this
-#ifdef isascii
-#undef isascii
-#endif
-
 namespace __vic { namespace ascii {
 
 //----------------------------------------------------------------------------
@@ -81,7 +76,7 @@ __VIC_CONSTEXPR_FUNC bool iscntrl(char c)
     return (0 <= c && c <= '\x1F') || c == '\x7F';
 }
 //----------------------------------------------------------------------------
-__VIC_CONSTEXPR_FUNC bool isascii(char c)
+__VIC_CONSTEXPR_FUNC bool (isascii)(char c)
 {
     return static_cast<unsigned char>(c) < 0x7FU;
 }

+ 5 - 3
include/__vic/readonly_cstring.h

@@ -30,10 +30,12 @@ public:
     readonly_cstring(const readonly_cstring &s) : st(dup(s.st)) {}
     ~readonly_cstring() noexcept; // for error.h
 
-    readonly_cstring &operator=(const char * );
-    readonly_cstring &operator=(const readonly_cstring & );
-    readonly_cstring &assign(const char * , const char * );
+    readonly_cstring &operator=(const char *s) { return assign(s); }
+    readonly_cstring &operator=(const readonly_cstring &s) { return assign(s.st); }
+    readonly_cstring &assign(const char *s) { return assign(s, size_t(-1)); }
     readonly_cstring &assign(const char * , size_t );
+    readonly_cstring &assign(const char *begin, const char *end)
+        { return assign(begin, end - begin); }
 
 #if __cpp_rvalue_references
     readonly_cstring(readonly_cstring &&s) noexcept : st(s.st) { s.st = nullptr; }

+ 42 - 0
include/__vic/type_traits.h

@@ -33,10 +33,35 @@ using std::remove_volatile;
 using std::remove_cv;
 using std::remove_reference;
 using std::remove_pointer;
+using std::conditional;
 using std::enable_if;
 
 //----------------------------------------------------------------------------
 
+#if __cpp_lib_logical_traits
+using std::conjunction;
+using std::disjunction;
+using std::negation;
+#elif __cpp_variadic_templates
+//----------------------------------------------------------------------------
+
+template<class...> struct conjunction : true_type {};
+template<class B1> struct conjunction<B1> : B1 {};
+template<class B1, class... Bn> struct conjunction<B1, Bn...> :
+    conditional<bool(B1::value), conjunction<Bn...>, B1>::type {};
+
+//----------------------------------------------------------------------------
+
+template<class...> struct disjunction : false_type {};
+template<class B1> struct disjunction<B1> : B1 {};
+template<class B1, class... Bn> struct disjunction<B1, Bn...> :
+    conditional<bool(B1::value), B1, disjunction<Bn...>>::type {};
+
+//----------------------------------------------------------------------------
+#endif
+
+//----------------------------------------------------------------------------
+
 #else // no <type_traits>
 
 //////////////////////////////////////////////////////////////////////////////
@@ -96,6 +121,14 @@ template<class T> struct remove_pointer<T *> { typedef T type; };
 
 //----------------------------------------------------------------------------
 
+template<bool Cond, class Then, class Else>
+struct conditional { typedef Then type; };
+
+template<class Then, class Else>
+struct conditional<false, Then, Else> { typedef Else type; };
+
+//----------------------------------------------------------------------------
+
 template<bool Test, class T = void>
 struct enable_if
 {
@@ -158,11 +191,20 @@ template<class T> using remove_volatile_t = typename remove_volatile<T>::type;
 template<class T> using remove_cv_t = typename remove_cv<T>::type;
 template<class T> using remove_reference_t = typename remove_reference<T>::type;
 template<class T> using remove_pointer_t = typename remove_pointer<T>::type;
+template<bool Cond, class Then, class Else>
+using conditional_t = typename conditional<Cond, Then, Else>::type;
 // No alias for enable_if because in C++11 SFINAE is not guaranteed
 #endif
 
 //----------------------------------------------------------------------------
 
+#if !__cpp_lib_logical_traits
+template<class B> struct negation :
+    integral_constant<bool, !bool(B::value)> {};
+#endif
+
+//----------------------------------------------------------------------------
+
 #if __cpp_lib_integer_sequence
 using std::index_sequence;
 using std::make_index_sequence;

+ 0 - 0
include/__vic/unicode.h


Some files were not shown because too many files changed in this diff