mirror of
https://github.com/ETLCPP/etl.git
synced 2026-11-09 22:59:47 +08:00
Merge branch 'feature/no_stl' into development
# Conflicts: # include/etl/algorithm.h # include/etl/stl/alternate/functional.h # test/test_no_stl_functional.cpp
This commit is contained in:
commit
9c4952f8c6
@ -617,7 +617,7 @@ namespace etl
|
||||
|
||||
for (TIterator1 i = begin1; i != end1; ++i)
|
||||
{
|
||||
#if ETL_CPP11_SUPPORTED
|
||||
#if ETL_CPP11_SUPPORTED && !defined(ETL_NO_STL)
|
||||
if (i == std::find_if(begin1, i, std::bind(predicate, *i, std::placeholders::_1)))
|
||||
#else
|
||||
if (i == std::find_if(begin1, i, std::bind1st(predicate, *i)))
|
||||
@ -654,7 +654,7 @@ namespace etl
|
||||
{
|
||||
for (TIterator1 i = begin1; i != end1; ++i)
|
||||
{
|
||||
#if ETL_CPP11_SUPPORTED
|
||||
#if ETL_CPP11_SUPPORTED && !defined(ETL_NO_STL)
|
||||
if (i == std::find_if(begin1, i, std::bind(predicate, *i, std::placeholders::_1)))
|
||||
#else
|
||||
if (i == std::find_if(begin1, i, std::bind1st(predicate, *i)))
|
||||
|
||||
@ -49,6 +49,90 @@ namespace std
|
||||
return lhs != rhs;
|
||||
}
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
|
||||
template <typename TArgumentType, typename TResultType>
|
||||
struct unary_function
|
||||
{
|
||||
typedef TArgumentType aurgument_type;
|
||||
typedef TResultType result_type;
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
|
||||
template <typename TFirstArgumentType, typename TSecondArgumentType, typename TResultType>
|
||||
struct binary_function
|
||||
{
|
||||
typedef TFirstArgumentType first_aurgument_type;
|
||||
typedef TSecondArgumentType second_aurgument_type;
|
||||
typedef TResultType result_type;
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
|
||||
template <typename TFunction>
|
||||
class binder1st : public etlstd::unary_function<typename TFunction::second_argument_type, typename TFunction::result_type>
|
||||
{
|
||||
protected:
|
||||
|
||||
TFunction operation;
|
||||
typename TFunction::first_argument_type value;
|
||||
|
||||
public:
|
||||
|
||||
binder1st(const TFunction& f, const typename TFunction::first_argument_type& v)
|
||||
: operation (f), value(v)
|
||||
{
|
||||
}
|
||||
|
||||
typename TFunction::result_type operator()(typename TFunction::second_argument_type& x) const
|
||||
{
|
||||
return operation(value, x);
|
||||
}
|
||||
|
||||
typename TFunction::result_type operator()(const typename TFunction::second_argument_type& x) const
|
||||
{
|
||||
return operation(value, x);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename F, typename T>
|
||||
binder1st<F> bind1st(const F& f, const T& x)
|
||||
{
|
||||
return binder1st<F>(f, x);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
|
||||
template <typename TFunction >
|
||||
class binder2nd : public etlstd::unary_function<typename TFunction::first_argument_type, typename TFunction::result_type>
|
||||
{
|
||||
protected:
|
||||
TFunction operation;
|
||||
typename TFunction::second_argument_type value;
|
||||
public:
|
||||
binder2nd(const TFunction& f, const typename TFunction::second_argument_type& v)
|
||||
: operation (f), value(v)
|
||||
{
|
||||
}
|
||||
|
||||
typename TFunction::result_type operator()(typename TFunction::first_argument_type& x) const
|
||||
{
|
||||
return operation(x, value);
|
||||
}
|
||||
|
||||
typename TFunction::result_type operator()(const typename TFunction::first_argument_type& x) const
|
||||
{
|
||||
return operation(x, value);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename F, typename T>
|
||||
binder2nd<F> bind2nd(const F& f, const T& x)
|
||||
{
|
||||
return binder2nd<F>(f, x);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -41,6 +41,14 @@ namespace
|
||||
return TCompare()(a, b);
|
||||
}
|
||||
|
||||
struct test : std::binary_function<int, int, bool>
|
||||
{
|
||||
bool operator()(int a, int b) const
|
||||
{
|
||||
return a < b;
|
||||
}
|
||||
};
|
||||
|
||||
SUITE(test_no_stl_functional)
|
||||
{
|
||||
//*************************************************************************
|
||||
@ -74,5 +82,19 @@ namespace
|
||||
CHECK((compare<etlstd::not_equal_to<int>>(1, 2)));
|
||||
CHECK((compare<etlstd::not_equal_to<int>>(2, 1)));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_bind1st)
|
||||
{
|
||||
CHECK((etlstd::bind1st(test(), 1)(2)));
|
||||
CHECK(!(etlstd::bind1st(test(), 2)(1)));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_bind2nd)
|
||||
{
|
||||
CHECK(!(etlstd::bind2nd(test(), 1)(2)));
|
||||
CHECK((etlstd::bind2nd(test(), 2)(1)));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user