public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* please approval my patch - add new logical traits to type_traits for logical completeness
@ 2019-02-09  4:19 李苏旺
  2019-02-09  7:15 ` Marc Glisse
  0 siblings, 1 reply; 4+ messages in thread
From: 李苏旺 @ 2019-02-09  4:19 UTC (permalink / raw)
  To: libstdc++, gcc-patches, gcc-testresults

hi all,

     I have a patch about libstdc++
include/std/type_traits ,
testsuite/20_util/logical_traits/requirements/explicit_instantiation.cc
testsuite/20_util/logical_traits/requirements/typedefs.cc
testsuite/20_util/logical_traits/value.cc,
 the patch want to add new logical traits , such as exclusive_or ,
not_exclusive_or, not_conjunction and not_disjunction for logical
completeness , the detail patch as below:
Index: ChangeLog
===================================================================
--- ChangeLog (revision 268714)
+++ ChangeLog (working copy)
@@ -1,3 +1,12 @@
+2019-02-09  lisuwang  <suwangli82@gmail.com>
+ * include/std/type_traits(__xor_<..>, excluesive_or<...>,
not_exclusive_or<...>, not_conjunction<...>, not_disjunction<...>): Define.
+ * testsuite/20_util/logical_traits/value.cc: Add
+ additional cases for std::not_conjunction, std::not_disjunction,
std::excluesive_or and std::not_exclusive_or.
+ *
testsuite/20_util/logical_traits/requirements/explicit_instantiation.cc: Add
+ explicit_instantiation of std::not_conjunction, std::not_disjunction,
std::excluesive_or and std::not_exclusive_or.
+ * testsuite/20_util/logical_traits/requirements/typedefs.cc: Add
+ the additional test cases to verify the typedefs.
+
 2019-02-09  Jonathan Wakely  <jwakely@redhat.com>

  PR libstdc++/71044
Index: include/std/type_traits
===================================================================
--- include/std/type_traits (revision 268714)
+++ include/std/type_traits (working copy)
@@ -142,6 +142,29 @@
     : public __bool_constant<!bool(_Pp::value)>
     { };

+  template<typename ...>
+    struct __xor_;
+
+  template<>
+ struct __xor_<>
+ : public true_type
+ { };
+
+  template<typename _B1>
+    struct __xor_<_B1>
+ : public _B1
+ { };
+
+  template<typename _B1, typename _B2>
+    struct __xor_<_B1, _B2>
+ : public __and_<__or_<_B1, _B2>,__not_<__and_<_B1, _B2>>>
+ { };
+
+  template<typename _B1, typename _B2, typename _B3, typename... _Bn>
+    struct __xor_<_B1, _B2,_B3,_Bn...>
+ : public __and_<__or_<_B1,__xor_<_B2,_B3,_Bn...>>,
__not_<__and_<_B1,__xor_<_B2,_B3,_Bn...>>>>
+ { };
+
 #if __cplusplus >= 201703L

   template<typename... _Bn>
@@ -148,6 +171,10 @@
     inline constexpr bool __or_v = __or_<_Bn...>::value;
   template<typename... _Bn>
     inline constexpr bool __and_v = __and_<_Bn...>::value;
+  template<typename... _Bn>
+    inline constexpr bool __not_v = __not_<_Bn...>::value;
+  template<typename... _Bn>
+    inline constexpr bool __xor_v = __xor_<_Bn...>::value;

 #define __cpp_lib_logical_traits 201510

@@ -165,8 +192,27 @@
     struct negation
     : __not_<_Pp>
     { };
-
   template<typename... _Bn>
+    struct exclusive_or
+ : __xor_<_Bn...>
+ { };
+
+  template<typename... _Bn>
+    struct not_conjunction
+ : __not_<__and_<_Bn...>
+ { };
+
+  template<typename... _Bn>
+    struct not_disjunction
+ : __not_<__or_<_Bn...>>
+ { };
+
+  template<typename... _Bn>
+    struct not_exclusive_or
+ : __not_<__xor_<_Bn...>>
+ { };
+
+  template<typename... _Bn>
     inline constexpr bool conjunction_v = conjunction<_Bn...>::value;

   template<typename... _Bn>
@@ -174,6 +220,18 @@

   template<typename _Pp>
     inline constexpr bool negation_v = negation<_Pp>::value;
+
+  template<typename... _Bn>
+    inline constexpr bool exclusive_or_v = exclusive_or<_Bn...>::value;
+
+  template<typename... _Bn>
+    inline constexpr bool not_conjunction_v =
not_conjunction<_Bn...>::value;
+
+  template<typename... _Bn>
+    inline constexpr bool not_disjunction_v =
not_disjunction<_Bn...>::value;
+
+  template<typename... _Bn>
+    inline constexpr bool not_exclusive_or_v =
not_exclusive_or<_Bn...>::value;

 #endif // C++17

Index:
testsuite/20_util/logical_traits/requirements/explicit_instantiation.cc
===================================================================
--- testsuite/20_util/logical_traits/requirements/explicit_instantiation.cc
(revision
268714)
+++ testsuite/20_util/logical_traits/requirements/explicit_instantiation.cc
(working
copy)
@@ -27,4 +27,8 @@
   template struct conjunction<true_type, true_type>;
   template struct disjunction<false_type, true_type>;
   template struct negation<false_type>;
+  template struct excluesive_or<true_type, true_type>;
+  template struct not_exclusive_or<true_type, true_type>;
+  template struct not_conjunction<true_type, true_type>;
+  template struct not_disjunction<false_type, true_type>;
 }
Index: testsuite/20_util/logical_traits/requirements/typedefs.cc
===================================================================
--- testsuite/20_util/logical_traits/requirements/typedefs.cc (revision
268714)
+++ testsuite/20_util/logical_traits/requirements/typedefs.cc (working copy)
@@ -53,3 +53,43 @@
   typedef test_type::type::value_type         type_value_type;
   typedef test_type::type::type               type_type;
 }
+
+void test04()
+{
+  // Check for required typedefs
+  typedef std::not_conjunction<std::true_type, std::true_type>
test_type;
+  typedef test_type::value_type               value_type;
+  typedef test_type::type                     type;
+  typedef test_type::type::value_type         type_value_type;
+  typedef test_type::type::type               type_type;
+}
+
+void test05()
+{
+  // Check for required typedefs
+  typedef std::not_disjunction<std::false_type, std::true_type>
test_type;
+  typedef test_type::value_type               value_type;
+  typedef test_type::type                     type;
+  typedef test_type::type::value_type         type_value_type;
+  typedef test_type::type::type               type_type;
+}
+
+void test06()
+{
+  // Check for required typedefs
+  typedef std::excluesive_or<std::true_type, std::true_type>
test_type;
+  typedef test_type::value_type               value_type;
+  typedef test_type::type                     type;
+  typedef test_type::type::value_type         type_value_type;
+  typedef test_type::type::type               type_type;
+}
+
+void test07()
+{
+  // Check for required typedefs
+  typedef std::not_exclusive_or<std::true_type, std::true_type>
test_type;
+  typedef test_type::value_type               value_type;
+  typedef test_type::type                     type;
+  typedef test_type::type::value_type         type_value_type;
+  typedef test_type::type::type               type_type;
+}
Index: testsuite/20_util/logical_traits/value.cc
===================================================================
--- testsuite/20_util/logical_traits/value.cc (revision 268714)
+++ testsuite/20_util/logical_traits/value.cc (working copy)
@@ -25,21 +25,57 @@
   static_assert(std::negation<std::false_type>{});
   static_assert(!std::negation<std::true_type>{});
   static_assert(std::conjunction<>{});
+  static_assert(!std::not_conjunction<>{});
   static_assert(!std::disjunction<>{});
+  static_assert(std::not_disjunction<>{});
   static_assert(std::conjunction<std::true_type>{});
+  static_assert(!std::not_conjunction<std::true_type>{});
   static_assert(!std::conjunction<std::false_type>{});
+  static_assert(std::not_conjunction<std::false_type>{});
   static_assert(std::disjunction<std::true_type>{});
+  static_assert(!std::not_disjunction<std::true_type>{});
   static_assert(!std::disjunction<std::false_type>{});
+  static_assert(std::not_disjunction<std::false_type>{});
   static_assert(std::conjunction<std::true_type, std::true_type>{});
+  static_assert(!std::not_conjunction<std::true_type, std::true_type>{});
   static_assert(!std::conjunction<std::true_type, std::false_type>{});
+  static_assert(std::not_conjunction<std::true_type, std::false_type>{});
   static_assert(std::disjunction<std::false_type, std::true_type>{});
+  static_assert(!std::not_disjunction<std::false_type, std::true_type>{});
   static_assert(!std::disjunction<std::false_type, std::false_type>{});
+  static_assert(std::not_disjunction<std::false_type, std::false_type>{});
   static_assert(std::conjunction<std::true_type, std::true_type,
                 std::true_type>{});
+  static_assert(!std::not_conjunction<std::true_type, std::true_type,
+                std::true_type>{});
   static_assert(!std::conjunction<std::true_type, std::true_type,
                 std::false_type>{});
+  static_assert(std::not_conjunction<std::true_type, std::true_type,
+                std::false_type>{});
   static_assert(std::disjunction<std::false_type, std::false_type,
                 std::true_type>{});
+  static_assert(!std::not_disjunction<std::false_type, std::false_type,
+                std::true_type>{});
   static_assert(!std::disjunction<std::false_type, std::false_type,
                 std::false_type>{});
+  static_assert(std::not_disjunction<std::false_type, std::false_type,
+                std::false_type>{});
+  static_assert(std::exclusive_or<>{});
+  static_assert(std::exclusive_or<std::true_type>{});
+  static_assert(!std::exclusive_or<std::false_type>{});
+  static_assert(!std::exclusive_or<std::true_type, std::true_type>{});
+  static_assert(std::exclusive_or<std::false_type, std::true_type>{});
+  static_assert(!std::exclusive_or<std::false_type, std::false_type>{});
+  static_assert(std::exclusive_or<std::true_type, std::false_type>{});
+  static_assert(std::exclusive_or<std::true_type, std::true_type,
std::true_type>{});
+  static_assert(!std::exclusive_or<std::true_type, std::true_type,
std::false_type>{});
+  static_assert(!std::not_exclusive_or<>{});
+  static_assert(!std::not_exclusive_or<std::true_type>{});
+  static_assert(std::not_exclusive_or<std::false_type>{});
+  static_assert(std::not_exclusive_or<std::true_type, std::true_type>{});
+  static_assert(!std::not_exclusive_or<std::false_type, std::true_type>{});
+  static_assert(std::not_exclusive_or<std::false_type, std::false_type>{});
+  static_assert(!std::not_exclusive_or<std::true_type, std::false_type>{});
+  static_assert(!std::not_exclusive_or<std::false_type, std::false_type,
std::true_type>{});
+  static_assert(std::not_exclusive_or<std::false_type, std::false_type,
std::false_type>{});
 }

could you please approval my patch or check ? thank you in advance

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: please approval my patch - add new logical traits to type_traits for logical completeness
  2019-02-09  4:19 please approval my patch - add new logical traits to type_traits for logical completeness 李苏旺
@ 2019-02-09  7:15 ` Marc Glisse
  2019-02-10  3:46   ` 李苏旺
  0 siblings, 1 reply; 4+ messages in thread
From: Marc Glisse @ 2019-02-09  7:15 UTC (permalink / raw)
  To: 李苏旺; +Cc: libstdc++, gcc-patches

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; format=flowed; charset=GB2312, Size: 866 bytes --]

(removing gcc-testresults@ which is for (automated) results of running the 
testsuite, not for patch submission)

On Sat, 9 Feb 2019, ÀîËÕÍú wrote:

>     I have a patch about libstdc++
> include/std/type_traits ,
> testsuite/20_util/logical_traits/requirements/explicit_instantiation.cc
> testsuite/20_util/logical_traits/requirements/typedefs.cc
> testsuite/20_util/logical_traits/value.cc,
> the patch want to add new logical traits , such as exclusive_or ,
> not_exclusive_or, not_conjunction and not_disjunction for logical
> completeness , the detail patch as below:

Hello,

could you say where in the C++ standard these are specified? What paper 
added them, and what is the corresponding feature macro? If those are 
traits that you invented yourself, you will need to get them into the 
standard before we can add them to libstdc++.

-- 
Marc Glisse

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: please approval my patch - add new logical traits to type_traits for logical completeness
  2019-02-09  7:15 ` Marc Glisse
@ 2019-02-10  3:46   ` 李苏旺
  2019-02-11 11:59     ` Jonathan Wakely
  0 siblings, 1 reply; 4+ messages in thread
From: 李苏旺 @ 2019-02-10  3:46 UTC (permalink / raw)
  To: marc.glisse; +Cc: libstdc++, gcc-patches

hi Marc,
    I am very glad to receive you reply, in fact , I have neither "  C++
standard these are specified" nor "feature test macro" , I saw negation,
conjunction and disjunction have added in type_traits , and similar , after
I reference to
https://whatis.techtarget.com/definition/logic-gate-AND-OR-XOR-NOT-NAND-NOR-and-XNOR#xnor
  , I think  XOR(exclusive_or), NAND(not_conjunction),
NOR(not_disjunction), XNOR(not_exclusive_or) can be added in type_traits ,
that is all . any way , thank you reminder , maybe I may write a proposal
in the future , I hope these logical gates can be added too

your sincere
lisuwang


Marc Glisse <marc.glisse@inria.fr> 于2019年2月9日周六 下午3:14写道:

> (removing gcc-testresults@ which is for (automated) results of running
> the
> testsuite, not for patch submission)
>
> On Sat, 9 Feb 2019, 李苏旺 wrote:
>
> >     I have a patch about libstdc++
> > include/std/type_traits ,
> > testsuite/20_util/logical_traits/requirements/explicit_instantiation.cc
> > testsuite/20_util/logical_traits/requirements/typedefs.cc
> > testsuite/20_util/logical_traits/value.cc,
> > the patch want to add new logical traits , such as exclusive_or ,
> > not_exclusive_or, not_conjunction and not_disjunction for logical
> > completeness , the detail patch as below:
>
> Hello,
>
> could you say where in the C++ standard these are specified? What paper
> added them, and what is the corresponding feature macro? If those are
> traits that you invented yourself, you will need to get them into the
> standard before we can add them to libstdc++.
>
> --
> Marc Glisse
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: please approval my patch - add new logical traits to type_traits for logical completeness
  2019-02-10  3:46   ` 李苏旺
@ 2019-02-11 11:59     ` Jonathan Wakely
  0 siblings, 0 replies; 4+ messages in thread
From: Jonathan Wakely @ 2019-02-11 11:59 UTC (permalink / raw)
  To: 李苏旺; +Cc: marc.glisse, libstdc++, gcc-patches

On 10/02/19 11:46 +0800, 李苏旺 wrote:
>hi Marc,
>    I am very glad to receive you reply, in fact , I have neither "  C++
>standard these are specified" nor "feature test macro" , I saw negation,
>conjunction and disjunction have added in type_traits , and similar , after
>I reference to
>https://whatis.techtarget.com/definition/logic-gate-AND-OR-XOR-NOT-NAND-NOR-and-XNOR#xnor
>  , I think  XOR(exclusive_or), NAND(not_conjunction),
>NOR(not_disjunction), XNOR(not_exclusive_or) can be added in type_traits ,
>that is all . any way , thank you reminder , maybe I may write a proposal
>in the future , I hope these logical gates can be added too

I agree with Marc that we don't want to add these, unless they are
first added to the C++ standard (and I don't think they are useful
enough to add to the standard either).

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-02-11 11:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-09  4:19 please approval my patch - add new logical traits to type_traits for logical completeness 李苏旺
2019-02-09  7:15 ` Marc Glisse
2019-02-10  3:46   ` 李苏旺
2019-02-11 11:59     ` Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).