Write a report that: Introduces functors Provides an overview of functors Explains the need to implement generalised functors Discusses di erent generalised functor implementations, including at...

1 answer below »
Write a report that: Introduces functors Provides an overview of functors Explains the need to implement generalised functors Discusses di erent generalised functor implementations, including at least Boost and the variations pro-vided by the di erent C++ standards Compare the di erent functor implementations in terms of their functionality to the implementationproposed by Alexandrescu Compare the implementation of the one that most closely matches the functionality provided by theAlexandrescu implementation in terms of implementation Discusses features that may be in the C++ 17/20 standard that will improve the implementation of theimplementation that most closely matches that of Alexandrescu but have not been implemented.
Answered Same DayApr 01, 2021

Answer To: Write a report that: Introduces functors Provides an overview of functors Explains the need to...

Deepti answered on Apr 07 2021
128 Votes
Functors
1. Introduction
Functors are function Objects or Functionals that work as function. Functors include normal functions, pointers to function as well class objects where fun
ction call operator is overloaded. In other words, those classes for which function operator()() is defined. The advantage of a functor is that it is an object thus capable of containing state, either on a particular instance or across all instances.
In a layman’s perspective, a functor can be compared to a kind of box which maps a function to data and creates a transformed box. Functors are mostly used for sequences with usual mapping on each element. Functors are parameterized over the data type of those object contained by them. Functor in C++ is a class which is called using the same syntax as used for a function. The equivalent syntax is shown below:
MyFunctor (10);
MyFunctor. operator ()(10);
In general, a functor is anything (set of values to be precise) that can be mapped over and can be created out of almost any value. In a simple example, an array is mapped over. Therefore it can be considered as a functor. A functor may or may not hold one or a set of values. It may contain values which may be virtual, not present during the interaction. Another simple example is a wrapper class whose instances wrap a value. But it comes with a constraint that the instance should wrap only one value.
Class MyWrapper{
    Constructor (value) {
        This.value = value
    }
}
Array can be mapped over thus behaving as a functor, as shown below:
const addfour = (x) => x + 4
const array = [ 1, 2, 3 ]
const ArrayMapping = array.map(addfour)
console.log (ArrayMapping)        //=> [5, 6, 7]
The concept of functors is used in all the programming languages. However, it is expressed in better way in some.
2. Overview
An object...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here