File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -280,6 +280,16 @@ using if_byte_insertable = bool_if<
280280 std::is_base_of<std_vector<uint8_t >, Type>::value ||
281281 std::is_base_of<std::vector<uint8_t >, Type>::value>;
282282
283+ // / define: DEFINE_HAS_METHOD(flush)
284+ // / usage: bool_if<has_flush_v<Type>>
285+ #define DEFINE_HAS_METHOD (method ) \
286+ template <typename T, typename = void > \
287+ struct has_ ##method : std::false_type {}; \
288+ template <typename T> \
289+ struct has_ ##method<T, std::void_t <decltype (&T::method)>> : std::true_type {}; \
290+ template <typename Type> \
291+ static constexpr bool has_##method##_v = has_##method<Type>::value
292+
283293} // namespace libbitcoin
284294
285295#endif
Original file line number Diff line number Diff line change @@ -183,8 +183,9 @@ BC_PUSH_WARNING(NO_DYNAMIC_ARRAY_INDEXING)
183183BC_PUSH_WARNING (NO_ARRAY_INDEXING)
184184
185185template <size_t Size>
186- struct text_t
186+ class text_t
187187{
188+ public:
188189 std::array<uint8_t , Size - 1 > data;
189190 CONSTEVAL text_t (const char (&string)[Size]) noexcept
190191 : data(to_array(string)) {}
Original file line number Diff line number Diff line change @@ -652,4 +652,21 @@ static_assert(is_defined<if_byte_insertable<std_vector<uint8_t>>>);
652652// //static_assert(!is_defined<if_byte_insertable<std::array<uint8_t, 42>>>);
653653// //static_assert(!is_defined<if_byte_insertable<std::u32string>>);
654654// //static_assert(!is_defined<if_byte_insertable<std_vector<uint32_t>>>);
655- // //static_assert(!is_defined<if_byte_insertable<uint32_t>>);
655+ // //static_assert(!is_defined<if_byte_insertable<uint32_t>>);
656+
657+ // HAS_METHOD
658+
659+ struct not_has { void foobar_ () {} };
660+ struct has_args { void foobar (bool , int ) {} };
661+ struct has_base { void foobar () {} };
662+ struct has_publics_derived : public has_base {};
663+ struct has_protect_derived : protected has_base {};
664+ struct has_private_derived : private has_base {};
665+
666+ DEFINE_HAS_METHOD (foobar);
667+ static_assert (!has_foobar_v<not_has>);
668+ static_assert (has_foobar_v<has_args>);
669+ static_assert (has_foobar_v<has_base>);
670+ static_assert (has_foobar_v<has_publics_derived>);
671+ static_assert (!has_foobar_v<has_protect_derived>);
672+ static_assert (!has_foobar_v<has_private_derived>);
You can’t perform that action at this time.
0 commit comments