<commit_before>/*
 * Copyright(c) Sophist Solutions, Inc. 1990-2015.  All rights reserved
 */
#ifndef _Stroika_Foundation_Configuration_Concept_h_
#define _Stroika_Foundation_Configuration_Concept_h_   1

#include    "../StroikaPreComp.h"

#include    <iterator>          // needed for std::begin/std::end calls
#include    <type_traits>

#include    "../Configuration/Common.h"



/*
 *
 *  \version    <a href="code_status.html#Alpha">Alpha</a>
 *
 * Description:
 *
 *
 *
 * TODO:
 *      @todo   Maybe put concepts in sub-namespace Concept {} - and then list them out here? Instead of the _ stuff?
 *
 *      @todo   Think out if/when qCheckConceptRequirements SB defined? See if it takes up any runtime space/time? And decide
 *              according to that!
 *
 *      @todo   I think the RequireConceptAppliesToTypeInFunction can be replaced with RequireConceptAppliesToTypeMemberOfClass,
 *              and then both renamed to something simpler... test...
 *
 *
 * Notes:
 *
 *
 *
 */



/**
 */
#ifndef qCheckConceptRequirements
#define qCheckConceptRequirements 1
#endif



namespace   Stroika {
    namespace   Foundation {
        namespace   Configuration {


            /**
             *  LIFTED -@todo add docs/reference
             *  from Stroustrup C++11 book - page 800
             */
            struct substitution_failure {};


            /**
             *  LIFTED -@todo add docs/reference
             *  from Stroustrup C++11 book - page 800
             */
            template <typename T> struct substitution_succeeded : std::true_type {};
            template <> struct substitution_succeeded<substitution_failure> : std::false_type {};


            /**
             *  \brief  Define has_XXX (where you specify XXX) class which has a 'value' field saying
             *          if the XXX property is present.
             *
             *  Since I cannot (so far figure out how to) do in a single simple statement/template,
             *  at least do this magic in a macro...
             */
#define STROIKA_FOUNDATION_CONFIGURATION_DEFINE_HAS(NAME,XTEST)\
    namespace Private_ {\
        template    <typename T>\
        struct  NAME##_result_impl {\
            template    <typename X>\
            static auto check(const X& x) -> decltype(XTEST);\
            static Stroika::Foundation::Configuration::substitution_failure check(...);\
            using type = decltype(check(declval<T>()));\
        };\
    }\
    template    <typename T>\
    using   NAME##_result = typename Private_::NAME##_result_impl<T>::type;\
    template    <typename T>\
    struct  has_##NAME : integral_constant <bool, not is_same<NAME##_result<T>, Stroika::Foundation::Configuration::substitution_failure>::value> {};


            /*
             *  BASED ON
             *      http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3701.pdf
             *
             *  But not in standard yet, and these not well documented. So go with definitions in
             *      http://en.cppreference.com/w/cpp/concept/
             *  for now
             *
             *  Starting to experiment...
             */
            STROIKA_FOUNDATION_CONFIGURATION_DEFINE_HAS(eq, (x == x));
            STROIKA_FOUNDATION_CONFIGURATION_DEFINE_HAS(neq, (x != x));
            STROIKA_FOUNDATION_CONFIGURATION_DEFINE_HAS(lt, (x < x));

            /*
             *  has_beginend<T>::value is true iff T has a begin/end method
             *  @todo fix so checks results act more like iterators - subclass from iterator_tag>
             */
            STROIKA_FOUNDATION_CONFIGURATION_DEFINE_HAS(beginend, (std::begin (x) != std::end (x)));

            /*
             *  has_beginend<T>::value is true iff T has a begin/end method
             *  @todo fix so checks results act more like iterators - subclass from iterator_tag>
             */
            STROIKA_FOUNDATION_CONFIGURATION_DEFINE_HAS(begin, std::begin (x));


            /**
             *  Would like to use constexpr function (as with c++14 concepts) - but cannot due to weakness in constexpr support (absense) for vs2k13
             */
            namespace Private_ {
                template    <
                    typename ITERABLE_OF_T,
                    typename T,
                    typename ITER_RESULT_TYPE = begin_result<ITERABLE_OF_T>,
                    typename T2 = typename enable_if <
                        has_beginend<ITERABLE_OF_T>::value and
                        std::is_convertible<typename std::iterator_traits<ITER_RESULT_TYPE>::value_type, T>::value
                        >::type
                    >
                struct  IsIterableOfT_ : substitution_succeeded <T2> {
                };
            }
            template    <typename ITERABLE_OF_T, typename T>
            using  IsIterableOfT = Private_::IsIterableOfT_ <ITERABLE_OF_T, T>;


            /**
             *  See http://en.cppreference.com/w/cpp/concept/Container
             */
            template    <typename T>
            constexpr bool  Container ()
            {
#if 1
               // no where near enough, but a start...
				// IsIterableOfT<T>::value would be closer, but until we fix the SFINAE bug with that - that it doesnt compile instead of returning false - we msut use has_beginend
                return has_beginend<T>::value;
#else
                // about right?
                return IsIterableOfT<T>::value;
#endif
            }


            /**
             *  See http://en.cppreference.com/w/cpp/concept/EqualityComparable
             */
            template    <typename T>
            constexpr bool  EqualityComparable ()
            {
                return has_eq<T>::value && is_convertible<eq_result<T>, bool>::value;
            }

<commit_msg>rewrote Concept IsIterable<> - testing<commit_after>/*
 * Copyright(c) Sophist Solutions, Inc. 1990-2015.  All rights reserved
 */
#ifndef _Stroika_Foundation_Configuration_Concept_h_
#define _Stroika_Foundation_Configuration_Concept_h_   1

#include    "../StroikaPreComp.h"

#include    <iterator>          // needed for std::begin/std::end calls
#include    <type_traits>

#include    "../Configuration/Common.h"



/*
 *
 *  \version    <a href="code_status.html#Alpha">Alpha</a>
 *
 * Description:
 *
 *
 *
 * TODO:
 *      @todo   Maybe put concepts in sub-namespace Concept {} - and then list them out here? Instead of the _ stuff?
 *
 *      @todo   Think out if/when qCheckConceptRequirements SB defined? See if it takes up any runtime space/time? And decide
 *              according to that!
 *
 *      @todo   I think the RequireConceptAppliesToTypeInFunction can be replaced with RequireConceptAppliesToTypeMemberOfClass,
 *              and then both renamed to something simpler... test...
 *
 *
 * Notes:
 *
 *
 *
 */



/**
 */
#ifndef qCheckConceptRequirements
#define qCheckConceptRequirements 1
#endif



namespace   Stroika {
    namespace   Foundation {
        namespace   Configuration {


            /**
             *  LIFTED -@todo add docs/reference
             *  from Stroustrup C++11 book - page 800
             */
            struct substitution_failure {};


            /**
             *  LIFTED -@todo add docs/reference
             *  from Stroustrup C++11 book - page 800
             */
            template <typename T> struct substitution_succeeded : std::true_type {};
            template <> struct substitution_succeeded<substitution_failure> : std::false_type {};


            /**
             *  \brief  Define has_XXX (where you specify XXX) class which has a 'value' field saying
             *          if the XXX property is present.
             *
             *  Since I cannot (so far figure out how to) do in a single simple statement/template,
             *  at least do this magic in a macro...
             */
#define STROIKA_FOUNDATION_CONFIGURATION_DEFINE_HAS(NAME,XTEST)\
    namespace Private_ {\
        template    <typename T>\
        struct  NAME##_result_impl {\
            template    <typename X>\
            static auto check(const X& x) -> decltype(XTEST);\
            static Stroika::Foundation::Configuration::substitution_failure check(...);\
            using type = decltype(check(declval<T>()));\
        };\
    }\
    template    <typename T>\
    using   NAME##_result = typename Private_::NAME##_result_impl<T>::type;\
    template    <typename T>\
    struct  has_##NAME : integral_constant <bool, not is_same<NAME##_result<T>, Stroika::Foundation::Configuration::substitution_failure>::value> {};


            /*
             *  BASED ON
             *      http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3701.pdf
             *
             *  But not in standard yet, and these not well documented. So go with definitions in
             *      http://en.cppreference.com/w/cpp/concept/
             *  for now
             *
             *  Starting to experiment...
             */
            STROIKA_FOUNDATION_CONFIGURATION_DEFINE_HAS(eq, (x == x));
            STROIKA_FOUNDATION_CONFIGURATION_DEFINE_HAS(neq, (x != x));
            STROIKA_FOUNDATION_CONFIGURATION_DEFINE_HAS(lt, (x < x));

            /*
             *  has_beginend<T>::value is true iff T has a begin/end method
             *  @todo fix so checks results act more like iterators - subclass from iterator_tag>
             */
            STROIKA_FOUNDATION_CONFIGURATION_DEFINE_HAS(beginend, (std::begin (x) != std::end (x)));

            /*
             *  has_beginend<T>::value is true iff T has a begin/end method
             *  @todo fix so checks results act more like iterators - subclass from iterator_tag>
             */
            STROIKA_FOUNDATION_CONFIGURATION_DEFINE_HAS(begin, std::begin (x));


            /**
             *  Would like to use constexpr function (as with c++14 concepts) - but cannot due to weakness in constexpr support (absense) for vs2k13
             */
            namespace Private_ {
                template    <
                    typename ITERABLE_OF_T,
                    typename T,
                    typename ITER_RESULT_TYPE = begin_result<ITERABLE_OF_T>,
                    typename T2 = typename enable_if <
                        has_beginend<ITERABLE_OF_T>::value and
                        std::is_convertible<typename std::iterator_traits<ITER_RESULT_TYPE>::value_type, T>::value
                        >::type
                    >
                struct  IsIterableOfT_ : substitution_succeeded <T2> {
                };
                template    <
                    typename ITERABLE_OF_T,
                    typename T
                    >
                struct  T_result_impl_ {
                    template    <typename X>
                    static auto check(const X& x) ->
                    typename std::conditional <
                    has_beginend<ITERABLE_OF_T>::value and
                    std::is_convertible<typename std::iterator_traits<begin_result<ITERABLE_OF_T>>::value_type, T>::value,
                        substitution_succeeded <T>,
                        substitution_failure
                        >::type
                        ;
                    static substitution_failure check (...);
                    using type = decltype(check(declval<T>()));
                };
            }
            //template    <typename ITERABLE_OF_T, typename T>
            //using  IsIterableOfT = Private_::IsIterableOfT_ <ITERABLE_OF_T, T>;
            template    <typename ITERABLE_OF_T, typename T>
            using  IsIterableOfT2 = std::integral_constant <bool, not std::is_same <typename Private_::T_result_impl_<ITERABLE_OF_T, T>::type, substitution_failure>::value>;

            template    <typename ITERABLE_OF_T, typename T>
            using  IsIterableOfT = std::integral_constant <bool, not std::is_same <typename Private_::T_result_impl_<ITERABLE_OF_T, T>::type, substitution_failure>::value>;


            /**
             *  See http://en.cppreference.com/w/cpp/concept/Container
             */
            template    <typename T>
            constexpr bool  Container ()
            {
#if 1
                // no where near enough, but a start...
                // IsIterableOfT<T>::value would be closer, but until we fix the SFINAE bug with that - that it doesnt compile instead of returning false - we msut use has_beginend
                return has_beginend<T>::value;
#else
                // about right?
                return IsIterableOfT<T>::value;
#endif
            }


            /**
             *  See http://en.cppreference.com/w/cpp/concept/EqualityComparable
             */
            template    <typename T>
            constexpr bool  EqualityComparable ()
            {
                return has_eq<T>::value && is_convertible<eq_result<T>, bool>::value;
            }


{'fraction_non_alphanumeric': 0.09346663566612416, 'fraction_numerical': 0.006432612570719988, 'mean_word_length': 1.7774429616874732, 'pattern_counts': {'":': 0, '<': 93, '<?xml version=': 0, '>': 98, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1215581', 'n_tokens_mistral': 3722, 'n_tokens_neox': 3439, 'n_words': 899}