381 std::vector<std::function <result_t(arguments_t...)>>
functions;
390 bool completed_synchronously()
const noexcept override;
391 bool is_completed()
const noexcept override;
427 delegate(
const no_arguments_function_t& function)
noexcept {data_->no_arguments_functions.push_back(function);}
433 template<
class object1_t,
class object2_t>
434 delegate(
const object1_t&
object, result_t(object2_t::*method)()
const) noexcept {
435 data_->functions.push_back(
function_t(std::bind(method,
const_cast<object1_t*
>(&
object))));
434 delegate(
const object1_t&
object, result_t(object2_t::*method)()
const) noexcept {
…}
441 template<
class object1_t,
class object2_t>
442 delegate(
const object1_t&
object, result_t(object2_t::*method)()) noexcept {
443 data_->functions.push_back(
function_t(std::bind(method,
const_cast<object1_t*
>(&
object))));
442 delegate(
const object1_t&
object, result_t(object2_t::*method)()) noexcept {
…}
448 template<
class object1_t,
class object2_t,
class a1_t>
449 delegate(
const object1_t&
object, result_t(object2_t::*method)(a1_t)
const)
noexcept {
450 data_->functions.push_back(function_t(std::bind(method,
const_cast<object1_t*
>(&
object), std::placeholders::_1)));
453 template<
class object1_t,
class object2_t,
class a1_t>
454 delegate(
const object1_t&
object, result_t(object2_t::*method)(a1_t))
noexcept {
455 data_->functions.push_back(function_t(std::bind(method,
const_cast<object1_t*
>(&
object), std::placeholders::_1)));
458 template<
class object1_t,
class object2_t,
class a1_t,
class a2_t>
459 delegate(
const object1_t&
object, result_t(object2_t::*method)(a1_t, a2_t)
const)
noexcept {
460 data_->functions.push_back(function_t(std::bind(method,
const_cast<object1_t*
>(&
object), std::placeholders::_1, std::placeholders::_2)));
463 template<
class object1_t,
class object2_t,
class a1_t,
class a2_t>
464 delegate(
const object1_t&
object, result_t(object2_t::*method)(a1_t, a2_t))
noexcept {
465 data_->functions.push_back(function_t(std::bind(method,
const_cast<object1_t*
>(&
object), std::placeholders::_1, std::placeholders::_2)));
468 template<
class object1_t,
class object2_t,
class a1_t,
class a2_t,
class a3_t>
469 delegate(
const object1_t&
object, result_t(object2_t::*method)(a1_t, a2_t, a3_t)
const)
noexcept {
470 data_->functions.push_back(function_t(std::bind(method,
const_cast<object1_t*
>(&
object), std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)));
473 template<
class object1_t,
class object2_t,
class a1_t,
class a2_t,
class a3_t>
474 delegate(
const object1_t&
object, result_t(object2_t::*method)(a1_t, a2_t, a3_t))
noexcept {
475 data_->functions.push_back(function_t(std::bind(method,
const_cast<object1_t*
>(&
object), std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)));
478 template<
class object1_t,
class object2_t,
class a1_t,
class a2_t,
class a3_t,
class a4_t>
479 delegate(
const object1_t&
object, result_t(object2_t::*method)(a1_t, a2_t, a3_t, a4_t)
const) {
480 data_->functions.push_back(function_t(std::bind(method,
const_cast<object1_t*
>(&
object), std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4)));
483 template<
class object1_t,
class object2_t,
class a1_t,
class a2_t,
class a3_t,
class a4_t>
484 delegate(
const object1_t&
object, result_t(object2_t::*method)(a1_t, a2_t, a3_t, a4_t))
noexcept {
485 data_->functions.push_back(function_t(std::bind(method,
const_cast<object1_t*
>(&
object), std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4)));
488 template<
class object1_t,
class object2_t,
class a1_t,
class a2_t,
class a3_t,
class a4_t,
class A5>
489 delegate(
const object1_t&
object, result_t(object2_t::*method)(a1_t, a2_t, a3_t, a4_t, A5)
const)
noexcept {
490 data_->functions.push_back(function_t(std::bind(method,
const_cast<object1_t*
>(&
object), std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5)));
493 template<
class object1_t,
class object2_t,
class a1_t,
class a2_t,
class a3_t,
class a4_t,
class A5>
494 delegate(
const object1_t&
object, result_t(object2_t::*method)(a1_t, a2_t, a3_t, a4_t, A5)) {
495 data_->functions.push_back(function_t(std::bind(method,
const_cast<object1_t*
>(&
object), std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5)));
498 template<
class object1_t,
class object2_t,
class a1_t,
class a2_t,
class a3_t,
class a4_t,
class A5,
class a6_t>
499 delegate(
const object1_t&
object, result_t(object2_t::*method)(a1_t, a2_t, a3_t, a4_t, A5, a6_t)
const)
noexcept {
500 data_->functions.push_back(function_t(std::bind(method,
const_cast<object1_t*
>(&
object), std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5, std::placeholders::_6)));
503 template<
class object1_t,
class object2_t,
class a1_t,
class a2_t,
class a3_t,
class a4_t,
class A5,
class a6_t>
504 delegate(
const object1_t&
object, result_t(object2_t::*method)(a1_t, a2_t, a3_t, a4_t, A5, a6_t))
noexcept {
505 data_->functions.push_back(function_t(std::bind(method,
const_cast<object1_t*
>(&
object), std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5, std::placeholders::_6)));
508 template<
class object1_t,
class object2_t,
class a1_t,
class a2_t,
class a3_t,
class a4_t,
class A5,
class a6_t,
class a7_t>
509 delegate(
const object1_t&
object, result_t(object2_t::*method)(a1_t, a2_t, a3_t, a4_t, A5, a6_t, a7_t)
const)
noexcept {
510 data_->functions.push_back(function_t(std::bind(method,
const_cast<object1_t*
>(&
object), std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5, std::placeholders::_6, std::placeholders::_7)));
513 template<
class object1_t,
class object2_t,
class a1_t,
class a2_t,
class a3_t,
class a4_t,
class A5,
class a6_t,
class a7_t>
514 delegate(
const object1_t&
object, result_t(object2_t::*method)(a1_t, a2_t, a3_t, a4_t, A5, a6_t, a7_t))
noexcept {
515 data_->functions.push_back(function_t(std::bind(method,
const_cast<object1_t*
>(&
object), std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5, std::placeholders::_6, std::placeholders::_7)));
518 template<
class object1_t,
class object2_t,
class a1_t,
class a2_t,
class a3_t,
class a4_t,
class A5,
class a6_t,
class a7_t,
class a8_t>
519 delegate(
const object1_t&
object, result_t(object2_t::*method)(a1_t, a2_t, a3_t, a4_t, A5, a6_t, a7_t, a8_t)
const)
noexcept {
520 data_->functions.push_back(function_t(std::bind(method,
const_cast<object1_t*
>(&
object), std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5, std::placeholders::_6, std::placeholders::_7, std::placeholders::_8)));
523 template<
class object1_t,
class object2_t,
class a1_t,
class a2_t,
class a3_t,
class a4_t,
class A5,
class a6_t,
class a7_t,
class a8_t>
524 delegate(
const object1_t&
object, result_t(object2_t::*method)(a1_t, a2_t, a3_t, a4_t, A5, a6_t, a7_t, a8_t))
noexcept {
525 data_->functions.push_back(function_t(std::bind(method,
const_cast<object1_t*
>(&
object), std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5, std::placeholders::_6, std::placeholders::_7, std::placeholders::_8)));
528 template<
class object1_t,
class object2_t,
class a1_t,
class a2_t,
class a3_t,
class a4_t,
class A5,
class a6_t,
class a7_t,
class a8_t,
class a9_t>
529 delegate(
const object1_t&
object, result_t(object2_t::*method)(a1_t, a2_t, a3_t, a4_t, A5, a6_t, a7_t, a8_t, a9_t)
const)
noexcept {
530 data_->functions.push_back(function_t(std::bind(method,
const_cast<object1_t*
>(&
object), std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5, std::placeholders::_6, std::placeholders::_7, std::placeholders::_8, std::placeholders::_9)));
533 template<
class object1_t,
class object2_t,
class a1_t,
class a2_t,
class a3_t,
class a4_t,
class A5,
class a6_t,
class a7_t,
class a8_t,
class a9_t>
534 delegate(
const object1_t&
object, result_t(object2_t::*method)(a1_t, a2_t, a3_t, a4_t, A5, a6_t, a7_t, a8_t, a9_t))
noexcept {
535 data_->functions.push_back(function_t(std::bind(method,
const_cast<object1_t*
>(&
object), std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5, std::placeholders::_6, std::placeholders::_7, std::placeholders::_8, std::placeholders::_9)));
538 template<
class object1_t,
class object2_t,
class a1_t,
class a2_t,
class a3_t,
class a4_t,
class A5,
class a6_t,
class a7_t,
class a8_t,
class a9_t,
class a10_t>
539 delegate(
const object1_t&
object, result_t(object2_t::*method)(a1_t, a2_t, a3_t, a4_t, A5, a6_t, a7_t, a8_t, a9_t, a10_t)
const)
noexcept {
540 data_->functions.push_back(function_t(std::bind(method,
const_cast<object1_t*
>(&
object), std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5, std::placeholders::_6, std::placeholders::_7, std::placeholders::_8, std::placeholders::_9, std::placeholders::_10)));
543 template<
class object1_t,
class object2_t,
class a1_t,
class a2_t,
class a3_t,
class a4_t,
class A5,
class a6_t,
class a7_t,
class a8_t,
class a9_t,
class a10_t>
544 delegate(
const object1_t&
object, result_t(object2_t::*method)(a1_t, a2_t, a3_t, a4_t, A5, a6_t, a7_t, a8_t, a9_t, a10_t))
noexcept {
545 data_->functions.push_back(function_t(std::bind(method,
const_cast<object1_t*
>(&
object), std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5, std::placeholders::_6, std::placeholders::_7, std::placeholders::_8, std::placeholders::_9, std::placeholders::_10)));
562 bool is_empty() const noexcept {
return data_->functions.size() == 0 && data_->no_arguments_functions.size() == 0;}
566 size_t size() const noexcept {
return data_->functions.size() + data_->no_arguments_functions.size();}
620 if (data_->functions.size() !=
other.data_->functions.size() || data_->no_arguments_functions.size() !=
other.data_->no_arguments_functions.size())
623 for (
size_t i = 0;
i < data_->no_arguments_functions.size();
i++)
624 if (!are_equals(data_->no_arguments_functions[
i],
other.data_->no_arguments_functions[
i]))
627 for (
size_t i = 0;
i < data_->functions.size();
i++)
628 if (!are_equals(data_->functions[
i],
other.data_->functions[
i]))
647 result.data_->no_arguments_functions.push_back(function);
649 result.data_->functions.push_back(function);
662 result.data_->no_arguments_functions.push_back(function);
663 for (
const function_t& function :
b.data_->functions)
664 result.data_->functions.push_back(function);
675 std::for_each(value.data_->no_arguments_functions.begin(), value.data_->no_arguments_functions.end(), [&](
auto no_arguments_function) {
676 auto iterator = std::find_if(result.data_->no_arguments_functions.rbegin(), result.data_->no_arguments_functions.rend(), [&](auto item) {return are_equals(item, no_arguments_function);});
677 if (iterator != result.data_->no_arguments_functions.rend()) result.data_->no_arguments_functions.erase((iterator + 1).base());
680 std::for_each(value.data_->functions.begin(), value.data_->functions.end(), [&](
auto function) {
681 auto iterator = std::find_if(result.data_->functions.rbegin(), result.data_->functions.rend(), [&](auto item) {return are_equals(item, function);});
682 if (iterator != result.data_->functions.rend()) result.data_->functions.erase((iterator + 1).base());
695 if (find(result.data_->no_arguments_functions.begin(), result.data_->no_arguments_functions.end(), function) != result.data_->no_arguments_functions.end()) {
696 for (
typename function_collection::reverse_iterator iterator = result.data_->no_arguments_functions.rbegin(); iterator != result.data_->no_arguments_functions.rend(); ++iterator) {
697 if (are_equals(*iterator, function))
698 result.data_->no_arguments_functions.erase((iterator + 1).base());
703 for (
const function_t& function : value.data_->functions) {
704 if (find(result.data_->functions.begin(), result.data_->functions.end(), function) != result.data_->functions.end()) {
705 for (
typename function_collection::reverse_iterator iterator = result.data_->functions.rbegin(); iterator != result.data_->functions.rend(); ++iterator) {
706 if (are_equals(*iterator, function))
707 result.data_->functions.erase((iterator + 1).base());
722 if (data_->no_arguments_functions.size() == 0 && data_->functions.size() == 0)
return result_t();
724 if (data_->no_arguments_functions.size()) {
725 for (
size_t i = 0;
i < data_->no_arguments_functions.size() - (data_->functions.size() == 0 ? 1 : 0);
i++) {
727 data_->no_arguments_functions[
i]();
730 if (data_->functions.size() == 0) {
732 return data_->no_arguments_functions.back()();
736 for (
size_t i = 0;
i < data_->functions.size() - 1;
i++) {
738 data_->functions[
i](arguments...);
741 return data_->functions.back()(arguments...);
746 template<
class type_t>
747 delegate& operator =(
const type_t& function)
noexcept {
748 data_->no_arguments_functions.clear();
749 data_->functions.clear();
750 data_->functions.push_back(function_t(function));
754 delegate& operator =(
const function_t& function)
noexcept {
755 data_->no_arguments_functions.clear();
756 data_->functions.clear();
757 data_->functions.push_back(function);
761 delegate& operator =(
const no_arguments_function_t& function)
noexcept {
762 data_->no_arguments_functions.clear();
763 data_->functions.clear();
764 data_->no_arguments_functions.push_back(function);
768 delegate operator +(
const delegate& other)
noexcept {
769 delegate result = *
this;
774 delegate operator +(
const no_arguments_function_t& function)
noexcept {
775 delegate result = *
this;
780 delegate operator +(
const function_t& function)
noexcept {
781 delegate result = *
this;
787 delegate operator +(fn_t function)
noexcept {
788 delegate result = *
this;
793 delegate& operator +=(
const delegate& delegate)
noexcept {
794 *
this = delegate::combine(*
this, delegate);
798 delegate& operator +=(
const no_arguments_function_t& function)
noexcept {
799 *
this = delegate::combine(*
this, delegate(function));
803 delegate& operator +=(
const function_t& function)
noexcept {
804 *
this = delegate::combine(*
this, delegate(function));
809 delegate& operator +=(fn_t function)
noexcept {
810 *
this = delegate::combine(*
this, delegate(function));
814 delegate operator -(
const delegate& other)
noexcept {
815 delegate result = *
this;
820 delegate operator -(
const no_arguments_function_t& function)
noexcept {
821 delegate result = *
this;
826 delegate operator -(
const function_t& function)
noexcept {
827 delegate result = *
this;
833 delegate operator -(fn_t function)
noexcept {
834 delegate result = *
this;
839 delegate& operator -=(
const delegate& delegate)
noexcept {
840 *
this = delegate::remove(*
this, delegate);
844 delegate& operator -=(
const no_arguments_function_t& function)
noexcept {
845 *
this = delegate::remove(*
this, delegate(function));
849 delegate& operator -=(
const function_t& function)
noexcept {
850 *
this = delegate::remove(*
this, delegate(function));
855 delegate& operator -=(fn_t function)
noexcept {
856 *
this = delegate::remove(*
this, delegate(function));
862 static bool are_equals(
const std::function<result_t(arguments_t...)>& fct1,
const std::function<result_t(arguments_t...)>& fct2)
noexcept {
863 return fct1.target_type() == fct2.target_type() && (fct1.template target<result_t(*)(arguments_t...)>() == fct2.template target<result_t(*)(arguments_t...)>() || *fct1.template target<result_t(*)(arguments_t...)>() == *fct2.template target<result_t(*)(arguments_t...)>());
866 static bool are_equals(
const std::function<result_t()>& fct1,
const std::function<result_t()>& fct2)
noexcept {
867 return fct1.target_type() == fct2.target_type() && (fct1.template target<result_t(*)()>() == fct2.template target<result_t(*)()>() || *fct1.template target<result_t(*)()>() == *fct2.template target<result_t(*)()>());
870 static typename no_arguments_function_collection::const_iterator find(
typename no_arguments_function_collection::const_iterator begin,
typename no_arguments_function_collection::const_iterator end,
const no_arguments_function_t& function)
noexcept {
871 auto iterator = std::find_if(begin, end, [&](
auto item) {
return are_equals(item, function);});
872 if (iterator != end)
return iterator;
876 static typename function_collection::const_iterator find(
typename function_collection::const_iterator begin,
typename function_collection::const_iterator end,
const function_t& function)
noexcept {
877 auto iterator = std::find_if(begin, end, [&](
auto item) {
return are_equals(item, function);});
878 if (iterator != end)
return iterator;