mirror of
https://github.com/ETLCPP/etl.git
synced 2026-04-30 19:09:10 +08:00
function.h add const to operator () (#117)
Change-Id: Id70a05ab1bfdb95499a3c6622379c8bb639f5f40
This commit is contained in:
parent
5243b96d0b
commit
059159fe1f
@ -59,7 +59,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// The function operator that will be overridden.
|
||||
//*************************************************************************
|
||||
virtual void operator ()(TParameter) = 0;
|
||||
virtual void operator ()(TParameter) const = 0;
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
@ -76,7 +76,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// The function operator that will be overridden.
|
||||
//*************************************************************************
|
||||
virtual void operator ()() = 0;
|
||||
virtual void operator ()() const = 0;
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
@ -108,7 +108,7 @@ namespace etl
|
||||
/// The function operator that calls the destination function.
|
||||
///\param data The data to pass to the function.
|
||||
//*************************************************************************
|
||||
virtual void operator ()(TParameter data)
|
||||
virtual void operator ()(TParameter data) const
|
||||
{
|
||||
// Call the object's member function with the data.
|
||||
(p_object->*p_function)(data);
|
||||
@ -144,7 +144,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// The function operator that calls the destination function.
|
||||
//*************************************************************************
|
||||
virtual void operator ()()
|
||||
virtual void operator ()() const
|
||||
{
|
||||
// Call the object's member function.
|
||||
(p_object->*p_function)();
|
||||
@ -178,7 +178,7 @@ namespace etl
|
||||
/// The function operator that calls the destination function.
|
||||
///\param data The data to pass to the function.
|
||||
//*************************************************************************
|
||||
virtual void operator ()(TParameter data)
|
||||
virtual void operator ()(TParameter data) const
|
||||
{
|
||||
// Call the function with the data.
|
||||
(*p_function)(data);
|
||||
@ -210,7 +210,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// The function operator that calls the destination function.
|
||||
//*************************************************************************
|
||||
virtual void operator ()()
|
||||
virtual void operator ()() const
|
||||
{
|
||||
// Call the function.
|
||||
(*p_function)();
|
||||
@ -248,7 +248,7 @@ namespace etl
|
||||
/// The function operator that calls the destination function.
|
||||
///\param data The data to pass to the function.
|
||||
//*************************************************************************
|
||||
virtual void operator ()(TParameter data)
|
||||
virtual void operator ()(TParameter data) const
|
||||
{
|
||||
// Call the object's member function with the data.
|
||||
(p_object->*Function)(data);
|
||||
@ -286,7 +286,7 @@ namespace etl
|
||||
/// The function operator that calls the destination function.
|
||||
///\param data The data to pass to the function.
|
||||
//*************************************************************************
|
||||
virtual void operator ()()
|
||||
virtual void operator ()() const
|
||||
{
|
||||
// Call the object's member function.
|
||||
(p_object->*Function)();
|
||||
@ -315,7 +315,7 @@ namespace etl
|
||||
/// The function operator that calls the destination function.
|
||||
///\param data The data to pass to the function.
|
||||
//*************************************************************************
|
||||
virtual void operator ()(TParameter data)
|
||||
virtual void operator ()(TParameter data) const
|
||||
{
|
||||
// Call the object's member function with the data.
|
||||
(Instance.*Function)(data);
|
||||
@ -340,7 +340,7 @@ namespace etl
|
||||
/// The function operator that calls the destination function.
|
||||
///\param data The data to pass to the function.
|
||||
//*************************************************************************
|
||||
virtual void operator ()()
|
||||
virtual void operator ()() const
|
||||
{
|
||||
// Call the object's member function.
|
||||
(Instance.*Function)();
|
||||
@ -372,7 +372,7 @@ namespace etl
|
||||
/// The function operator that calls the destination function.
|
||||
///\param data The data to pass to the function.
|
||||
//*************************************************************************
|
||||
virtual void operator ()(TParameter data)
|
||||
virtual void operator ()(TParameter data) const
|
||||
{
|
||||
// Call the object's member function with the data.
|
||||
(*Function)(data);
|
||||
@ -404,7 +404,7 @@ namespace etl
|
||||
/// The function operator that calls the destination function.
|
||||
///\param data The data to pass to the function.
|
||||
//*************************************************************************
|
||||
virtual void operator ()()
|
||||
virtual void operator ()() const
|
||||
{
|
||||
// Call the function.
|
||||
(*Function)();
|
||||
|
||||
@ -51,6 +51,14 @@ void call(etl::ifunction<void>& function)
|
||||
function();
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
// Call the const function taking no parameters.
|
||||
//*****************************************************************************
|
||||
void call(const etl::ifunction<void>& function)
|
||||
{
|
||||
function();
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
// Call the function taking an int parameter.
|
||||
//*****************************************************************************
|
||||
@ -59,6 +67,14 @@ void call(etl::ifunction<int>& function)
|
||||
function(VALUE);
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
// Call the const function taking an int parameter.
|
||||
//*****************************************************************************
|
||||
void call(const etl::ifunction<int>& function)
|
||||
{
|
||||
function(VALUE);
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
// Call the function taking a Data parameter.
|
||||
//*****************************************************************************
|
||||
@ -69,6 +85,16 @@ void call(etl::ifunction<const Data&>& function)
|
||||
function(data);
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
// Call the const function taking a Data parameter.
|
||||
//*****************************************************************************
|
||||
void call(const etl::ifunction<const Data&>& function)
|
||||
{
|
||||
Data data;
|
||||
data.d = VALUE;
|
||||
function(data);
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
// The free function taking no parameters.
|
||||
//*****************************************************************************
|
||||
@ -145,6 +171,16 @@ namespace
|
||||
|
||||
call(function);
|
||||
|
||||
CHECK(function_called);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_const_free_void)
|
||||
{
|
||||
const etl::function<void, void> function(free_void);
|
||||
|
||||
call(function);
|
||||
|
||||
CHECK(function_called);
|
||||
}
|
||||
|
||||
@ -158,6 +194,17 @@ namespace
|
||||
CHECK(function_called);
|
||||
CHECK(parameter_correct);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_const_free_int)
|
||||
{
|
||||
const etl::function<void, int> function(free_int);
|
||||
|
||||
call(function);
|
||||
|
||||
CHECK(function_called);
|
||||
CHECK(parameter_correct);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_free_reference)
|
||||
@ -169,6 +216,17 @@ namespace
|
||||
CHECK(function_called);
|
||||
CHECK(parameter_correct);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_const_free_reference)
|
||||
{
|
||||
const etl::function<void, const Data&> function(free_reference);
|
||||
|
||||
call(function);
|
||||
|
||||
CHECK(function_called);
|
||||
CHECK(parameter_correct);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_free_void_compile_time)
|
||||
@ -179,6 +237,16 @@ namespace
|
||||
|
||||
CHECK(function_called);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_const_free_void_compile_time)
|
||||
{
|
||||
const etl::function_fv<free_void> function;
|
||||
|
||||
call(function);
|
||||
|
||||
CHECK(function_called);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_free_int_compile_time)
|
||||
@ -190,6 +258,17 @@ namespace
|
||||
CHECK(function_called);
|
||||
CHECK(parameter_correct);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_const_free_int_compile_time)
|
||||
{
|
||||
const etl::function_fp<int, free_int> function;
|
||||
|
||||
call(function);
|
||||
|
||||
CHECK(function_called);
|
||||
CHECK(parameter_correct);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_free_reference_compile_time)
|
||||
@ -201,6 +280,17 @@ namespace
|
||||
CHECK(function_called);
|
||||
CHECK(parameter_correct);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_const_free_reference_compile_time)
|
||||
{
|
||||
const etl::function_fp<const Data&, free_reference> function;
|
||||
|
||||
call(function);
|
||||
|
||||
CHECK(function_called);
|
||||
CHECK(parameter_correct);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_member_void)
|
||||
@ -212,6 +302,17 @@ namespace
|
||||
|
||||
CHECK(function_called);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_const_member_void)
|
||||
{
|
||||
Test test;
|
||||
const etl::function<Test, void> function(test, &Test::member_void);
|
||||
|
||||
call(function);
|
||||
|
||||
CHECK(function_called);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_member_int)
|
||||
@ -224,6 +325,18 @@ namespace
|
||||
CHECK(function_called);
|
||||
CHECK(parameter_correct);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_const_member_int)
|
||||
{
|
||||
Test test;
|
||||
const etl::function<Test, int> function(test, &Test::member_int);
|
||||
|
||||
call(function);
|
||||
|
||||
CHECK(function_called);
|
||||
CHECK(parameter_correct);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_member_reference)
|
||||
@ -236,6 +349,18 @@ namespace
|
||||
CHECK(function_called);
|
||||
CHECK(parameter_correct);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_const_member_reference)
|
||||
{
|
||||
Test test;
|
||||
const etl::function<Test, const Data&> function(test, &Test::member_reference);
|
||||
|
||||
call(function);
|
||||
|
||||
CHECK(function_called);
|
||||
CHECK(parameter_correct);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_member_void_compile_time)
|
||||
@ -247,6 +372,17 @@ namespace
|
||||
|
||||
CHECK(function_called);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_const_member_void_compile_time)
|
||||
{
|
||||
Test test;
|
||||
const etl::function_mv<Test, &Test::member_void> function(test);
|
||||
|
||||
call(function);
|
||||
|
||||
CHECK(function_called);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_member_int_compile_time)
|
||||
@ -259,6 +395,18 @@ namespace
|
||||
CHECK(function_called);
|
||||
CHECK(parameter_correct);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_const_member_int_compile_time)
|
||||
{
|
||||
Test test;
|
||||
const etl::function_mp<Test, int, &Test::member_int> function(test);
|
||||
|
||||
call(function);
|
||||
|
||||
CHECK(function_called);
|
||||
CHECK(parameter_correct);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_member_reference_compile_time)
|
||||
@ -271,6 +419,18 @@ namespace
|
||||
CHECK(function_called);
|
||||
CHECK(parameter_correct);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_const_member_reference_compile_time)
|
||||
{
|
||||
Test test;
|
||||
const etl::function_mp<Test, const Data&, &Test::member_reference> function(test);
|
||||
|
||||
call(function);
|
||||
|
||||
CHECK(function_called);
|
||||
CHECK(parameter_correct);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_instance_member_void_compile_time)
|
||||
@ -283,6 +443,18 @@ namespace
|
||||
|
||||
CHECK(function_called);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_const_instance_member_void_compile_time)
|
||||
{
|
||||
function_called = false;
|
||||
|
||||
const etl::function_imv<Test, test_static, &Test::member_void> function;
|
||||
|
||||
call(function);
|
||||
|
||||
CHECK(function_called);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_instance_member_parameter_compile_time)
|
||||
@ -295,6 +467,18 @@ namespace
|
||||
|
||||
CHECK(function_called);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_const_instance_member_parameter_compile_time)
|
||||
{
|
||||
function_called = false;
|
||||
|
||||
const etl::function_imp<Test, int, test_static, &Test::member_int> function;
|
||||
|
||||
call(function);
|
||||
|
||||
CHECK(function_called);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_instance_member_reference_compile_time)
|
||||
@ -307,5 +491,17 @@ namespace
|
||||
|
||||
CHECK(function_called);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_const_instance_member_reference_compile_time)
|
||||
{
|
||||
function_called = false;
|
||||
|
||||
const etl::function_imp<Test, const Data&, test_static, &Test::member_reference> function;
|
||||
|
||||
call(function);
|
||||
|
||||
CHECK(function_called);
|
||||
}
|
||||
};
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user