c 2b 2b template policy

Solutions on MaxInterview for c 2b 2b template policy by the best coders in the world

showing results for - "c 2b 2b template policy"
Aria
08 Jan 2020
1template<typename... Policies>
2class PolicyAndVariadic: public Policies...{};
3
4class PolicyOne
5{
6public:
7    void executePolicyOne()
8    {
9        std::cout << "execute PolicyOne" << std::endl;    
10    }
11};
12
13class PolicyTwo
14{
15public:
16    void executePolicyTwo()
17    {
18        std::cout << "execute PolicyTwo" << std::endl;
19    }
20};
21
22typedef PolicyAndVariadic<PolicyOne, PolicyTwo> PolicyOneAndPolicyTwo;
23
24PolicyOneAndPolicyTwo linstance;
25
26linstance.executePolicyOne();
27
28linstance.executePolicyTwo();
Louisa
09 Oct 2017
1template<typename... Policies>
2class PolicyAndVaradic: public Policies...
3{
4public:
5    template<typename... Args>
6    PolicyAndVaradic(const Args... Arg)
7        : Policies(Arg)...{}
8};
9
10class PolicyOne
11{
12    std::string mText;
13
14public:
15    PolicyOne(const char* aText):mText(aText){}
16    
17    void executePolicyOne()
18    {
19        std::cout << mText << std::endl;
20    }
21};
22
23class PolicyTwo
24{
25    std::string mText;
26public:
27
28    PolicyTwo(const char* aText):mText(aText){}
29
30    void executePolicyTwo()
31    {
32        std::cout << mText << std::endl;
33    }
34};
35
36PolicyOneAndPolicyTwo linstance("PolicyOne", "PolicyTwo");
37
38linstance.executePolicyOne();
39
40linstance.executePolicyTwo();
Jeannette
20 Mar 2019
1#include <iostream>
2#include <string>
3
4template <typename OutputPolicy, typename LanguagePolicy>
5class HelloWorld : private OutputPolicy, private LanguagePolicy {
6 public:
7  // Behavior method.
8  void Run() const {
9    // Two policy methods.
10    Print(Message());
11  }
12
13 private:
14  using LanguagePolicy::Message;
15  using OutputPolicy::Print;
16};
17
18class OutputPolicyWriteToCout {
19 protected:
20  template <typename MessageType>
21  void Print(MessageType&& message) const {
22    std::cout << message << std::endl;
23  }
24};
25
26class LanguagePolicyEnglish {
27 protected:
28  std::string Message() const { return "Hello, World!"; }
29};
30
31class LanguagePolicyGerman {
32 protected:
33  std::string Message() const { return "Hallo Welt!"; }
34};
35
36int main() {
37  // Example 1
38  using HelloWorldEnglish = HelloWorld<OutputPolicyWriteToCout, LanguagePolicyEnglish>;
39
40  HelloWorldEnglish hello_world;
41  hello_world.Run();  // Prints "Hello, World!".
42
43  // Example 2
44  // Does the same, but uses another language policy.
45  using HelloWorldGerman = HelloWorld<OutputPolicyWriteToCout, LanguagePolicyGerman>;
46
47  HelloWorldGerman hello_world2;
48  hello_world2.Run();  // Prints "Hallo Welt!".
49}
50
similar questions
queries leading to this page
c 2b 2b template policy