The title looks very long,
I mainly want to have two types of variables A and B, respectively. can I obtain a bool constant during compilation to show whether I have an operation like a = B.
#include <type_traits> template< typename = static_cast<Dest> std::declval<Src>()))> __test( template<typename, typename> template<typename TA, typename TB> __implicit_conv = __static_castable::__test< std::declval<TA> == std::declval<TB> ), >( template< typename = std::declval<TA> == std::declval<TB>())> __implicit_conv<TA, TB> __test( template<typename, typename> template<typename A, typename B> has_equal_operator = std::is_same< decltype(__has_equal_operator_impl::__test<A, B>())> }
Then let's take a look at the test results.
#include <iostream> template<typename A, typename B> std::cout << << bw::has_equal_operator<A, B>::value << == ( A&, B& A == ( A&, C& D == ( B&, C& output_result<A, B> output_result<B, A> output_result<A, C> output_result<B, C> output_result<, > output_result<, > output_result<, > output_result<decltype(std::cout), > }
What is the use of this? 0,
You will find that if you write something similar to delegate, there will be a lot of compilation errors when you delete a function (for example, a function like this does not have a comparison operator,
With this, we can provide different comparison behaviors based on whether the = Operator exists. If yes, we can use it. If no = Operator exists, we can use our own defined comparison behaviors (such as comparing memory or directly true)
Although the semantics cannot be guaranteed, it is better in some cases (such as delegate.