Re: please approval my patch - add new logical traits to type_traits for logical completeness

2019-02-11 Thread Jonathan Wakely

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).



Re: please approval my patch - add new logical traits to type_traits for logical completeness

2019-02-09 Thread 李苏旺
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  于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
>


Re: please approval my patch - add new logical traits to type_traits for logical completeness

2019-02-08 Thread Marc Glisse
(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


please approval my patch - add new logical traits to type_traits for logical completeness

2019-02-08 Thread 李苏旺
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  
+ * 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  

  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
 { };

+  template
+struct __xor_;
+
+  template<>
+ struct __xor_<>
+ : public true_type
+ { };
+
+  template
+struct __xor_<_B1>
+ : public _B1
+ { };
+
+  template
+struct __xor_<_B1, _B2>
+ : public __and_<__or_<_B1, _B2>,__not_<__and_<_B1, _B2>>>
+ { };
+
+  template
+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
@@ -148,6 +171,10 @@
 inline constexpr bool __or_v = __or_<_Bn...>::value;
   template
 inline constexpr bool __and_v = __and_<_Bn...>::value;
+  template
+inline constexpr bool __not_v = __not_<_Bn...>::value;
+  template
+inline constexpr bool __xor_v = __xor_<_Bn...>::value;

 #define __cpp_lib_logical_traits 201510

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

   template
@@ -174,6 +220,18 @@

   template
 inline constexpr bool negation_v = negation<_Pp>::value;
+
+  template
+inline constexpr bool exclusive_or_v = exclusive_or<_Bn...>::value;
+
+  template
+inline constexpr bool not_conjunction_v =
not_conjunction<_Bn...>::value;
+
+  template
+inline constexpr bool not_disjunction_v =
not_disjunction<_Bn...>::value;
+
+  template
+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;
   template struct disjunction;
   template struct negation;
+  template struct excluesive_or;
+  template struct not_exclusive_or;
+  template struct not_conjunction;
+  template struct not_disjunction;
 }
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
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
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