SlideShare a Scribd company logo
1 of 20
www.luxoft.com
Alexey Tsoy
Senior Developer
Meta programming in C++
www.luxoft.com
Introduction
Metaprogramming in C++ (Andrei Alexandrescu, 2002).
Templates:
• one of the most powerful part of C++
• quite new technology (just only 18 years old)
www.luxoft.comwww.luxoft.com
RPC diagram
www.luxoft.comwww.luxoft.com
struct calc_interface {
struct functions {
double add(double, double);
int eval(std::string);
};
struct signals {
void expr_evaluated(int, double);
};
};
Interface definition: Ideal case
www.luxoft.com
Example of usage
struct calc_server: server_t<calc_interface>
{
double add(double a, double b) override
{ return a + b; };
int eval(string expr) override {
static int id(0); ++id;
new std::thread( [this, expr, id] () {
sleep(100);
this->expr_evaluated(expr, 12345);
} );
return id;
}
};
client_t<calc_interface> client;
// subscribe to the signal ..
client.expr_evaluated(
[] (int id, string expr, double res)
{ cout << expr << "→" << res; }
);
// execute functions ..
cout << client.add(1,2) << endl;
client.add(1,2,
[] (double res) { cout << res << endl; })
www.luxoft.comwww.luxoft.com
struct calc_interface
{
RPC_FUNCTION(double(double, double), add);
RPC_FUNCTION(int(std::string), eval);
RPC_SIGNAL (void(int, double), expr_evaluated);
};
Interface definition: implemented case
www.luxoft.com
Usage
server_t<calc_interface> server(transpotr);
server_t::initialize(server)
.add_handler<calc_interface::add> (
[] (double a, double b) { return a + b;} )
.add_handler<calc_interface::eval> (
[] (string expr) → int {
static int id(0); ++id;
new std::thread( [this, expr, id] () {
sleep(100);
server.emit<expr_evaluated>(expr, 12345);
} );
return id;
});
client_t<calc_interface> client(transpotr);
// subscribe to the signal ..
client.subscribe<client_t::expr_evaluated>(
[] (int id, string expr, double res)
{ cout << expr << "→" << res; }
);
// execute functions ..
cout << client.invoke<add>(1,2) << endl;
// async invoke
client.invoke(1,2, [] (double res) { cout << res << endl;
})
www.luxoft.com
What should be taken into account
• Wrong function parameters. e.g. the following should cause a compile time
errors
– client.invoke<add>(“hello” , 123) or client.invoke<add>(1) or
client.invoke<add>(1, 2, 3)
• Execution of nonexistent function
– interface_1 { RPC_FN (void (int), fn1) };
– interface_2 { RPC_FN (void (double), fn2) };
– client_t<interface_1>().invoke<interface_2::fn2>(5.);
www.luxoft.com
Implementation
struct calc_interface
{
// RPC_FUNCTION(double(double, double), add);
struct add: meta_function_t<double (double, double), true>
{ static const char* uniq_name() { return “add”; } };
//RPC_FUNCTION(int(std::string), eval);
struct eval: meta_function_t<double (double, double), true>
{ static const char* uniq_name() { return “eval”; };
//RPC_SIGNAL (void(int, double), expr_evaluated);
struct expr_evaluated: meta_function_t<double (double, double), false>
{ static const char* uniq_name() { return “expr_evaluated”; };
};
meta_function_t < R (Arg0, …, ArgN) , bool> :: result_type → R;
meta_function_t < R (Arg0, …, ArgN) , bool> :: args_count → N;
meta_function_t < R (Arg0, …, ArgN) , bool> :: arg<0>::type → Arg0;
...
meta_function_t < R (Arg0, …, ArgN) , bool> :: arg<N>::type → ArgN;
meta_function_t < R (Arg0, …, ArgN) , bool> ::is_function → bool
www.luxoft.comwww.luxoft.com
namespace details {
template<typename... Args>
struct args_count
{ enum { value = 0 }; };
template<typename A1, typename ... Args>
struct args_count<A1, Args...>
{ enum { value = 1 + args_count<Args...>::value }; };}
cout << detail::args_count < >::value ; → 0
cout << detail::args_count < int >::value ; → 1
cout << detail::args_count < int , float>::value ; → 2
www.luxoft.comwww.luxoft.com
namepsace detail {
template<unsigned int N, typename ...Args>
struct arg;
template<typename A0, typename ...Args>
struct arg<0, A0, Args...>
{ typedef A0 type; };
template<unsigned int N, typename A0, typename ...Args>
struct arg<N, A0, Args...>
{ typedef typename arg<N - 1, Args...>::type type; };
}
detail::arg<0, int>::type → int
detail::arg<0, int, double>::type → int
detail::arg<1, int, double>::type → double
www.luxoft.comwww.luxoft.com
template<typename FnSygn, bool>
struct meta_function;
template<typename UniqType, bool isFn, typename R, typename ...Args>
struct meta_function<R(Args…), isFn>
{
typedef R result_type;
enum { args_count = detail::args_count<Args...>::value };
template<unsigned int N>
struct arg
{ typedef typename detail::arg<N, Args...>::type type; };
enum { is_function = isFn };
};
www.luxoft.com
client.invoke
// calc_interface
struct add: meta_function_t<double (double, double), true> { … };
// client_t<calc_interface> client:
…
auto result = client.invoke<add> ( … ) :
1) check arguments
2) serialize arguments
3) serialize function ID
4) send data
5) wait for response
6) deserialize and return result
www.luxoft.com
client.invoke
template< typename MetaFn, typename ...Args>
typename MetaFn::result_type invoke
( Args const&... args)
{
check if <MetaFn> declared in <calc_interface> ;
static_assert(MetaFn::is_function == true);
static_assert(MetaFn::args_count == detail::args_count<Args...>::value);
typename MetaFn::arg<0>::type a0 = get<0>(args...);
...
typename MetaFn::arg<N>::type a1 = get<N>(args...);
// ---->>>
auto ostream = transport.get_ostream( );
ostream << MetaFn::uniq_name()
<< arg0 << … << argN;
int sequence_id = transport.send(ostream);
transport_wait_for_response(sequence_id);
auto istream = transport.get_istream(sequence_id);
MetaFn::result_type result;
istream >> result;
return result;
}
www.luxoft.com
client.invoke
template<typename MetaFn, unsigned int N, typename IStream, typename ...Args>
void serrialize_all(IStream & , Args ...args) { };
template<typename MetaFn, unsigned int N, typename IStream, typename Arg0, typename ...Args>
void serrialize_all(IStream & stream, Arg0 const& arg0,Args ...args)
{
typename typedef MetaFn::arg<N>::type arg_to_send = arg0;
stream << arg0;
serrialize_all<MetaFn, N + 1> (stream, args...);
}
www.luxoft.com
client.invoke
template< typename MetaFn, typename ...Args>
typename MetaFn::result_type invoke ( Args const&... args )
{
check if <MetaFn> declared in <calc_interface> ;
static_assert(MetaFn::is_function == true);
static_assert(MetaFn::args_count == detail::args_count<Args...>::value);
auto ostream = transport.get_ostream( );
serrialize_all<MetaFn,0>(ostream, MetaFn::uniq_name(), args...);
int sequence_id = transport.send(ostream);
transport_wait_for_response(sequence_id);
auto istream = transport.get_istream(sequence_id);
MetaFn::result_type result;
istream >> result;
return result;
}
www.luxoft.com
Exists or not ?
struct calc_interface {
long __registrate_meta_type(…);
// RPC_FUNCTION(double(double, double), add);
struct add: meta_function_t<double (double, double), true>
{ static const char* uniq_name() { return “add”; } };
char __registrate_meta_type(add );
...
char __registrate_meta_type(expr_evaluated);
};
template< typename Interface, typename MetaFn> struct is_present {
enum { value = sizeof( ((Interface*)0)→
__registrate_meta_type(MetaFn())) == 1 ? 1 : 0 }; };
std::cout << is_present<calc_interface,
calc_interface::add>::value → 1
std::cout << is_present<calc_interface,
calc_interface::eval>::value → 1
std::cout << is_present<calc_interface, int>::value → 0
www.luxoft.com
Client.invoke – final version
//client_t<calc_interface> client;
// template<Interface> client_t { typedef Interface interface; };
template< typename MetaFn, typename ...Args>0
typename MetaFn::result_type invoke( Args const&... args ) {
static_assert(is_present<interface, MetaFn> :: value == 1);
static_assert(MetaFn::is_function == true);
static_assert(MetaFn::args_count == detail::args_count<Args...>::value);
auto ostream = transport.get_ostream( );
serrialize_all<MetaFn,0>(ostream, MetaFn::uniq_name(), args...);
int sequence_id = transport.send(ostream);
transport_wait_for_response(sequence_id);
auto istream = transport.get_istream(sequence_id);
MetaFn::result_type result;
istream >> result;
return result;
}
www.luxoft.comwww.luxoft.com
Tsoy Alexey
Mails:
atsoy@luxoft.com
tsoy.alexey@gmail.com
Contact details
www.luxoft.com
Thank you

More Related Content

What's hot

Java script advance-auroskills (2)
Java script advance-auroskills (2)Java script advance-auroskills (2)
Java script advance-auroskills (2)BoneyGawande
 
CBSE Class XII Comp sc practical file
CBSE Class XII Comp sc practical fileCBSE Class XII Comp sc practical file
CBSE Class XII Comp sc practical filePranav Ghildiyal
 
Коварный code type ITGM #9
Коварный code type ITGM #9Коварный code type ITGM #9
Коварный code type ITGM #9Andrey Zakharevich
 
Writing good std::future&lt;c++>
Writing good std::future&lt;c++>Writing good std::future&lt;c++>
Writing good std::future&lt;c++>Anton Bikineev
 
The Ring programming language version 1.7 book - Part 87 of 196
The Ring programming language version 1.7 book - Part 87 of 196The Ring programming language version 1.7 book - Part 87 of 196
The Ring programming language version 1.7 book - Part 87 of 196Mahmoud Samir Fayed
 
jq: JSON - Like a Boss
jq: JSON - Like a Bossjq: JSON - Like a Boss
jq: JSON - Like a BossBob Tiernay
 
The Ring programming language version 1.5.3 book - Part 91 of 184
The Ring programming language version 1.5.3 book - Part 91 of 184The Ring programming language version 1.5.3 book - Part 91 of 184
The Ring programming language version 1.5.3 book - Part 91 of 184Mahmoud Samir Fayed
 
响应式编程及框架
响应式编程及框架响应式编程及框架
响应式编程及框架jeffz
 
The Ring programming language version 1.9 book - Part 94 of 210
The Ring programming language version 1.9 book - Part 94 of 210The Ring programming language version 1.9 book - Part 94 of 210
The Ring programming language version 1.9 book - Part 94 of 210Mahmoud Samir Fayed
 
Статичный SQL в С++14. Евгений Захаров ➠ CoreHard Autumn 2019
Статичный SQL в С++14. Евгений Захаров ➠  CoreHard Autumn 2019Статичный SQL в С++14. Евгений Захаров ➠  CoreHard Autumn 2019
Статичный SQL в С++14. Евгений Захаров ➠ CoreHard Autumn 2019corehard_by
 
Introduction to JQ
Introduction to JQIntroduction to JQ
Introduction to JQKnoldus Inc.
 
Java script – basic auroskills (2)
Java script – basic   auroskills (2)Java script – basic   auroskills (2)
Java script – basic auroskills (2)BoneyGawande
 
The Evolution of Async-Programming (SD 2.0, JavaScript)
The Evolution of Async-Programming (SD 2.0, JavaScript)The Evolution of Async-Programming (SD 2.0, JavaScript)
The Evolution of Async-Programming (SD 2.0, JavaScript)jeffz
 
Category theory, Monads, and Duality in the world of (BIG) Data
Category theory, Monads, and Duality in the world of (BIG) DataCategory theory, Monads, and Duality in the world of (BIG) Data
Category theory, Monads, and Duality in the world of (BIG) Datagreenwop
 

What's hot (20)

Java script advance-auroskills (2)
Java script advance-auroskills (2)Java script advance-auroskills (2)
Java script advance-auroskills (2)
 
CBSE Class XII Comp sc practical file
CBSE Class XII Comp sc practical fileCBSE Class XII Comp sc practical file
CBSE Class XII Comp sc practical file
 
C program
C programC program
C program
 
Коварный code type ITGM #9
Коварный code type ITGM #9Коварный code type ITGM #9
Коварный code type ITGM #9
 
Writing good std::future&lt;c++>
Writing good std::future&lt;c++>Writing good std::future&lt;c++>
Writing good std::future&lt;c++>
 
The Ring programming language version 1.7 book - Part 87 of 196
The Ring programming language version 1.7 book - Part 87 of 196The Ring programming language version 1.7 book - Part 87 of 196
The Ring programming language version 1.7 book - Part 87 of 196
 
jq: JSON - Like a Boss
jq: JSON - Like a Bossjq: JSON - Like a Boss
jq: JSON - Like a Boss
 
The Ring programming language version 1.5.3 book - Part 91 of 184
The Ring programming language version 1.5.3 book - Part 91 of 184The Ring programming language version 1.5.3 book - Part 91 of 184
The Ring programming language version 1.5.3 book - Part 91 of 184
 
C programs
C programsC programs
C programs
 
响应式编程及框架
响应式编程及框架响应式编程及框架
响应式编程及框架
 
The Ring programming language version 1.9 book - Part 94 of 210
The Ring programming language version 1.9 book - Part 94 of 210The Ring programming language version 1.9 book - Part 94 of 210
The Ring programming language version 1.9 book - Part 94 of 210
 
Статичный SQL в С++14. Евгений Захаров ➠ CoreHard Autumn 2019
Статичный SQL в С++14. Евгений Захаров ➠  CoreHard Autumn 2019Статичный SQL в С++14. Евгений Захаров ➠  CoreHard Autumn 2019
Статичный SQL в С++14. Евгений Захаров ➠ CoreHard Autumn 2019
 
Introduction to JQ
Introduction to JQIntroduction to JQ
Introduction to JQ
 
C++ practical
C++ practicalC++ practical
C++ practical
 
Java script – basic auroskills (2)
Java script – basic   auroskills (2)Java script – basic   auroskills (2)
Java script – basic auroskills (2)
 
Static and const members
Static and const membersStatic and const members
Static and const members
 
The Evolution of Async-Programming (SD 2.0, JavaScript)
The Evolution of Async-Programming (SD 2.0, JavaScript)The Evolution of Async-Programming (SD 2.0, JavaScript)
The Evolution of Async-Programming (SD 2.0, JavaScript)
 
Jason parsing
Jason parsingJason parsing
Jason parsing
 
java sockets
 java sockets java sockets
java sockets
 
Category theory, Monads, and Duality in the world of (BIG) Data
Category theory, Monads, and Duality in the world of (BIG) DataCategory theory, Monads, and Duality in the world of (BIG) Data
Category theory, Monads, and Duality in the world of (BIG) Data
 

Similar to Meta Programming C++ RPC

Is your C# optimized
Is your C# optimizedIs your C# optimized
Is your C# optimizedWoody Pewitt
 
Applying Compiler Techniques to Iterate At Blazing Speed
Applying Compiler Techniques to Iterate At Blazing SpeedApplying Compiler Techniques to Iterate At Blazing Speed
Applying Compiler Techniques to Iterate At Blazing SpeedPascal-Louis Perez
 
用Tornado开发RESTful API运用
用Tornado开发RESTful API运用用Tornado开发RESTful API运用
用Tornado开发RESTful API运用Felinx Lee
 
Apache Spark in your likeness - low and high level customization
Apache Spark in your likeness - low and high level customizationApache Spark in your likeness - low and high level customization
Apache Spark in your likeness - low and high level customizationBartosz Konieczny
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript IntroductionDmitry Sheiko
 
Ensure code quality with vs2012
Ensure code quality with vs2012Ensure code quality with vs2012
Ensure code quality with vs2012Sandeep Joshi
 
Imugi: Compiler made with Python
Imugi: Compiler made with PythonImugi: Compiler made with Python
Imugi: Compiler made with PythonHan Lee
 
Apache Commons - Don\'t re-invent the wheel
Apache Commons - Don\'t re-invent the wheelApache Commons - Don\'t re-invent the wheel
Apache Commons - Don\'t re-invent the wheeltcurdt
 
SF Scala meet up, lighting talk: SPA -- Scala JDBC wrapper
SF Scala meet up, lighting talk: SPA -- Scala JDBC wrapperSF Scala meet up, lighting talk: SPA -- Scala JDBC wrapper
SF Scala meet up, lighting talk: SPA -- Scala JDBC wrapperChester Chen
 
ADG Poznań - Kotlin for Android developers
ADG Poznań - Kotlin for Android developersADG Poznań - Kotlin for Android developers
ADG Poznań - Kotlin for Android developersBartosz Kosarzycki
 
Implement the Queue ADT using array – based approach. Using C++ prog.pdf
Implement the Queue ADT using array – based approach. Using C++ prog.pdfImplement the Queue ADT using array – based approach. Using C++ prog.pdf
Implement the Queue ADT using array – based approach. Using C++ prog.pdfsktambifortune
 
Solve the coding errors for upvotemake test-statsg++ -g -std=c++.pdf
Solve the coding errors for upvotemake test-statsg++ -g -std=c++.pdfSolve the coding errors for upvotemake test-statsg++ -g -std=c++.pdf
Solve the coding errors for upvotemake test-statsg++ -g -std=c++.pdfsnewfashion
 
Analysis of Microsoft Code Contracts
Analysis of Microsoft Code ContractsAnalysis of Microsoft Code Contracts
Analysis of Microsoft Code ContractsPVS-Studio
 
Executing Sql Commands
Executing Sql CommandsExecuting Sql Commands
Executing Sql Commandsphanleson
 
Executing Sql Commands
Executing Sql CommandsExecuting Sql Commands
Executing Sql Commandsleminhvuong
 
ECMAScript 6 Review
ECMAScript 6 ReviewECMAScript 6 Review
ECMAScript 6 ReviewSperasoft
 
RESTful API using scalaz (3)
RESTful API using scalaz (3)RESTful API using scalaz (3)
RESTful API using scalaz (3)Yeshwanth Kumar
 

Similar to Meta Programming C++ RPC (20)

Bind me if you can
Bind me if you canBind me if you can
Bind me if you can
 
Is your C# optimized
Is your C# optimizedIs your C# optimized
Is your C# optimized
 
Applying Compiler Techniques to Iterate At Blazing Speed
Applying Compiler Techniques to Iterate At Blazing SpeedApplying Compiler Techniques to Iterate At Blazing Speed
Applying Compiler Techniques to Iterate At Blazing Speed
 
JPA 2.0
JPA 2.0JPA 2.0
JPA 2.0
 
用Tornado开发RESTful API运用
用Tornado开发RESTful API运用用Tornado开发RESTful API运用
用Tornado开发RESTful API运用
 
Apache Spark in your likeness - low and high level customization
Apache Spark in your likeness - low and high level customizationApache Spark in your likeness - low and high level customization
Apache Spark in your likeness - low and high level customization
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript Introduction
 
Ensure code quality with vs2012
Ensure code quality with vs2012Ensure code quality with vs2012
Ensure code quality with vs2012
 
Imugi: Compiler made with Python
Imugi: Compiler made with PythonImugi: Compiler made with Python
Imugi: Compiler made with Python
 
Apache Commons - Don\'t re-invent the wheel
Apache Commons - Don\'t re-invent the wheelApache Commons - Don\'t re-invent the wheel
Apache Commons - Don\'t re-invent the wheel
 
SF Scala meet up, lighting talk: SPA -- Scala JDBC wrapper
SF Scala meet up, lighting talk: SPA -- Scala JDBC wrapperSF Scala meet up, lighting talk: SPA -- Scala JDBC wrapper
SF Scala meet up, lighting talk: SPA -- Scala JDBC wrapper
 
ADG Poznań - Kotlin for Android developers
ADG Poznań - Kotlin for Android developersADG Poznań - Kotlin for Android developers
ADG Poznań - Kotlin for Android developers
 
Implement the Queue ADT using array – based approach. Using C++ prog.pdf
Implement the Queue ADT using array – based approach. Using C++ prog.pdfImplement the Queue ADT using array – based approach. Using C++ prog.pdf
Implement the Queue ADT using array – based approach. Using C++ prog.pdf
 
Solve the coding errors for upvotemake test-statsg++ -g -std=c++.pdf
Solve the coding errors for upvotemake test-statsg++ -g -std=c++.pdfSolve the coding errors for upvotemake test-statsg++ -g -std=c++.pdf
Solve the coding errors for upvotemake test-statsg++ -g -std=c++.pdf
 
Analysis of Microsoft Code Contracts
Analysis of Microsoft Code ContractsAnalysis of Microsoft Code Contracts
Analysis of Microsoft Code Contracts
 
Executing Sql Commands
Executing Sql CommandsExecuting Sql Commands
Executing Sql Commands
 
Executing Sql Commands
Executing Sql CommandsExecuting Sql Commands
Executing Sql Commands
 
ECMAScript 6 Review
ECMAScript 6 ReviewECMAScript 6 Review
ECMAScript 6 Review
 
WD programs descriptions.docx
WD programs descriptions.docxWD programs descriptions.docx
WD programs descriptions.docx
 
RESTful API using scalaz (3)
RESTful API using scalaz (3)RESTful API using scalaz (3)
RESTful API using scalaz (3)
 

More from LogeekNightUkraine

Autonomous driving on your developer pc. technologies, approaches, future
Autonomous driving on your developer pc. technologies, approaches, futureAutonomous driving on your developer pc. technologies, approaches, future
Autonomous driving on your developer pc. technologies, approaches, futureLogeekNightUkraine
 
Orkhan Gasimov "High Performance System Design"
Orkhan Gasimov "High Performance System Design" Orkhan Gasimov "High Performance System Design"
Orkhan Gasimov "High Performance System Design" LogeekNightUkraine
 
Vitalii Korzh "Managed Workflows or How to Master Data"
Vitalii Korzh "Managed Workflows or How to Master Data" Vitalii Korzh "Managed Workflows or How to Master Data"
Vitalii Korzh "Managed Workflows or How to Master Data" LogeekNightUkraine
 
Yevhen Tatarynov "From POC to High-Performance .NET applications"
Yevhen Tatarynov "From POC to High-Performance .NET applications"Yevhen Tatarynov "From POC to High-Performance .NET applications"
Yevhen Tatarynov "From POC to High-Performance .NET applications"LogeekNightUkraine
 
Oleksii Kuchuk "Reading gauge values with open cv imgproc"
Oleksii Kuchuk "Reading gauge values with open cv imgproc"Oleksii Kuchuk "Reading gauge values with open cv imgproc"
Oleksii Kuchuk "Reading gauge values with open cv imgproc"LogeekNightUkraine
 
Oleksandr Kutsan "Using katai struct to describe the process of working with ...
Oleksandr Kutsan "Using katai struct to describe the process of working with ...Oleksandr Kutsan "Using katai struct to describe the process of working with ...
Oleksandr Kutsan "Using katai struct to describe the process of working with ...LogeekNightUkraine
 
Pavlo Zhdanov "Mastering solid and base principles for software design"
Pavlo Zhdanov "Mastering solid and base principles for software design"Pavlo Zhdanov "Mastering solid and base principles for software design"
Pavlo Zhdanov "Mastering solid and base principles for software design"LogeekNightUkraine
 
Serhii Zemlianyi "Error Retries with Exponential Backoff Using RabbitMQ"
Serhii Zemlianyi "Error Retries with Exponential Backoff Using RabbitMQ"Serhii Zemlianyi "Error Retries with Exponential Backoff Using RabbitMQ"
Serhii Zemlianyi "Error Retries with Exponential Backoff Using RabbitMQ"LogeekNightUkraine
 
Iurii Antykhovych "Java and performance tools and toys"
Iurii Antykhovych "Java and performance tools and toys"Iurii Antykhovych "Java and performance tools and toys"
Iurii Antykhovych "Java and performance tools and toys"LogeekNightUkraine
 
Eugene Bova "Dapr (Distributed Application Runtime) in a Microservices Archit...
Eugene Bova "Dapr (Distributed Application Runtime) in a Microservices Archit...Eugene Bova "Dapr (Distributed Application Runtime) in a Microservices Archit...
Eugene Bova "Dapr (Distributed Application Runtime) in a Microservices Archit...LogeekNightUkraine
 
Aleksandr Kutsan "Managing Dependencies in C++"
Aleksandr Kutsan "Managing Dependencies in C++"Aleksandr Kutsan "Managing Dependencies in C++"
Aleksandr Kutsan "Managing Dependencies in C++"LogeekNightUkraine
 
Yevhen Tatarynov "My .NET Application Allocates too Much Memory. What Can I Do?"
Yevhen Tatarynov "My .NET Application Allocates too Much Memory. What Can I Do?"Yevhen Tatarynov "My .NET Application Allocates too Much Memory. What Can I Do?"
Yevhen Tatarynov "My .NET Application Allocates too Much Memory. What Can I Do?"LogeekNightUkraine
 
Alexandr Golyak, Nikolay Chertkov "Automotive Testing vs Test Automatio"
Alexandr Golyak, Nikolay Chertkov  "Automotive Testing vs Test Automatio"Alexandr Golyak, Nikolay Chertkov  "Automotive Testing vs Test Automatio"
Alexandr Golyak, Nikolay Chertkov "Automotive Testing vs Test Automatio"LogeekNightUkraine
 
Michal Kordas "Docker: Good, Bad or Both"
Michal Kordas "Docker: Good, Bad or Both"Michal Kordas "Docker: Good, Bad or Both"
Michal Kordas "Docker: Good, Bad or Both"LogeekNightUkraine
 
Kolomiyets Dmytro "Dealing with Multiple Caches, When Developing Microservices"
Kolomiyets Dmytro "Dealing with Multiple Caches, When Developing Microservices"Kolomiyets Dmytro "Dealing with Multiple Caches, When Developing Microservices"
Kolomiyets Dmytro "Dealing with Multiple Caches, When Developing Microservices"LogeekNightUkraine
 
Shestakov Illia "The Sandbox Theory"
Shestakov Illia "The Sandbox Theory"Shestakov Illia "The Sandbox Theory"
Shestakov Illia "The Sandbox Theory"LogeekNightUkraine
 
Dmytro Kochergin “Autotest with CYPRESS”
Dmytro Kochergin “Autotest with CYPRESS”Dmytro Kochergin “Autotest with CYPRESS”
Dmytro Kochergin “Autotest with CYPRESS”LogeekNightUkraine
 
Ivan Dryzhyruk “Ducks Don’t Like Bugs”
Ivan Dryzhyruk “Ducks Don’t Like Bugs”Ivan Dryzhyruk “Ducks Don’t Like Bugs”
Ivan Dryzhyruk “Ducks Don’t Like Bugs”LogeekNightUkraine
 

More from LogeekNightUkraine (20)

Face recognition with c++
Face recognition with c++ Face recognition with c++
Face recognition with c++
 
C++20 features
C++20 features C++20 features
C++20 features
 
Autonomous driving on your developer pc. technologies, approaches, future
Autonomous driving on your developer pc. technologies, approaches, futureAutonomous driving on your developer pc. technologies, approaches, future
Autonomous driving on your developer pc. technologies, approaches, future
 
Orkhan Gasimov "High Performance System Design"
Orkhan Gasimov "High Performance System Design" Orkhan Gasimov "High Performance System Design"
Orkhan Gasimov "High Performance System Design"
 
Vitalii Korzh "Managed Workflows or How to Master Data"
Vitalii Korzh "Managed Workflows or How to Master Data" Vitalii Korzh "Managed Workflows or How to Master Data"
Vitalii Korzh "Managed Workflows or How to Master Data"
 
Yevhen Tatarynov "From POC to High-Performance .NET applications"
Yevhen Tatarynov "From POC to High-Performance .NET applications"Yevhen Tatarynov "From POC to High-Performance .NET applications"
Yevhen Tatarynov "From POC to High-Performance .NET applications"
 
Oleksii Kuchuk "Reading gauge values with open cv imgproc"
Oleksii Kuchuk "Reading gauge values with open cv imgproc"Oleksii Kuchuk "Reading gauge values with open cv imgproc"
Oleksii Kuchuk "Reading gauge values with open cv imgproc"
 
Oleksandr Kutsan "Using katai struct to describe the process of working with ...
Oleksandr Kutsan "Using katai struct to describe the process of working with ...Oleksandr Kutsan "Using katai struct to describe the process of working with ...
Oleksandr Kutsan "Using katai struct to describe the process of working with ...
 
Pavlo Zhdanov "Mastering solid and base principles for software design"
Pavlo Zhdanov "Mastering solid and base principles for software design"Pavlo Zhdanov "Mastering solid and base principles for software design"
Pavlo Zhdanov "Mastering solid and base principles for software design"
 
Serhii Zemlianyi "Error Retries with Exponential Backoff Using RabbitMQ"
Serhii Zemlianyi "Error Retries with Exponential Backoff Using RabbitMQ"Serhii Zemlianyi "Error Retries with Exponential Backoff Using RabbitMQ"
Serhii Zemlianyi "Error Retries with Exponential Backoff Using RabbitMQ"
 
Iurii Antykhovych "Java and performance tools and toys"
Iurii Antykhovych "Java and performance tools and toys"Iurii Antykhovych "Java and performance tools and toys"
Iurii Antykhovych "Java and performance tools and toys"
 
Eugene Bova "Dapr (Distributed Application Runtime) in a Microservices Archit...
Eugene Bova "Dapr (Distributed Application Runtime) in a Microservices Archit...Eugene Bova "Dapr (Distributed Application Runtime) in a Microservices Archit...
Eugene Bova "Dapr (Distributed Application Runtime) in a Microservices Archit...
 
Aleksandr Kutsan "Managing Dependencies in C++"
Aleksandr Kutsan "Managing Dependencies in C++"Aleksandr Kutsan "Managing Dependencies in C++"
Aleksandr Kutsan "Managing Dependencies in C++"
 
Yevhen Tatarynov "My .NET Application Allocates too Much Memory. What Can I Do?"
Yevhen Tatarynov "My .NET Application Allocates too Much Memory. What Can I Do?"Yevhen Tatarynov "My .NET Application Allocates too Much Memory. What Can I Do?"
Yevhen Tatarynov "My .NET Application Allocates too Much Memory. What Can I Do?"
 
Alexandr Golyak, Nikolay Chertkov "Automotive Testing vs Test Automatio"
Alexandr Golyak, Nikolay Chertkov  "Automotive Testing vs Test Automatio"Alexandr Golyak, Nikolay Chertkov  "Automotive Testing vs Test Automatio"
Alexandr Golyak, Nikolay Chertkov "Automotive Testing vs Test Automatio"
 
Michal Kordas "Docker: Good, Bad or Both"
Michal Kordas "Docker: Good, Bad or Both"Michal Kordas "Docker: Good, Bad or Both"
Michal Kordas "Docker: Good, Bad or Both"
 
Kolomiyets Dmytro "Dealing with Multiple Caches, When Developing Microservices"
Kolomiyets Dmytro "Dealing with Multiple Caches, When Developing Microservices"Kolomiyets Dmytro "Dealing with Multiple Caches, When Developing Microservices"
Kolomiyets Dmytro "Dealing with Multiple Caches, When Developing Microservices"
 
Shestakov Illia "The Sandbox Theory"
Shestakov Illia "The Sandbox Theory"Shestakov Illia "The Sandbox Theory"
Shestakov Illia "The Sandbox Theory"
 
Dmytro Kochergin “Autotest with CYPRESS”
Dmytro Kochergin “Autotest with CYPRESS”Dmytro Kochergin “Autotest with CYPRESS”
Dmytro Kochergin “Autotest with CYPRESS”
 
Ivan Dryzhyruk “Ducks Don’t Like Bugs”
Ivan Dryzhyruk “Ducks Don’t Like Bugs”Ivan Dryzhyruk “Ducks Don’t Like Bugs”
Ivan Dryzhyruk “Ducks Don’t Like Bugs”
 

Recently uploaded

GREEN VEHICLES the kids picture show 2024
GREEN VEHICLES the kids picture show 2024GREEN VEHICLES the kids picture show 2024
GREEN VEHICLES the kids picture show 2024AHOhOops1
 
How To Fix Mercedes Benz Anti-Theft Protection Activation Issue
How To Fix Mercedes Benz Anti-Theft Protection Activation IssueHow To Fix Mercedes Benz Anti-Theft Protection Activation Issue
How To Fix Mercedes Benz Anti-Theft Protection Activation IssueTerry Sayther Automotive
 
Introduction of Basic of Paint Technology
Introduction of Basic of Paint TechnologyIntroduction of Basic of Paint Technology
Introduction of Basic of Paint TechnologyRaghavendraMishra19
 
Sales & Marketing Alignment_ How to Synergize for Success.pptx.pdf
Sales & Marketing Alignment_ How to Synergize for Success.pptx.pdfSales & Marketing Alignment_ How to Synergize for Success.pptx.pdf
Sales & Marketing Alignment_ How to Synergize for Success.pptx.pdfAggregage
 
加拿大温尼伯大学毕业证(UBC毕业证书)成绩单原版一比一
加拿大温尼伯大学毕业证(UBC毕业证书)成绩单原版一比一加拿大温尼伯大学毕业证(UBC毕业证书)成绩单原版一比一
加拿大温尼伯大学毕业证(UBC毕业证书)成绩单原版一比一nsrmw5ykn
 
Delhi Call Girls East Of Kailash 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls East Of Kailash 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls East Of Kailash 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls East Of Kailash 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Callshivangimorya083
 
如何办理爱尔兰都柏林大学毕业证(UCD毕业证) 成绩单原版一比一
如何办理爱尔兰都柏林大学毕业证(UCD毕业证) 成绩单原版一比一如何办理爱尔兰都柏林大学毕业证(UCD毕业证) 成绩单原版一比一
如何办理爱尔兰都柏林大学毕业证(UCD毕业证) 成绩单原版一比一mjyguplun
 
The 10th anniversary, Hyundai World Rally Team's amazing journey
The 10th anniversary, Hyundai World Rally Team's amazing journeyThe 10th anniversary, Hyundai World Rally Team's amazing journey
The 10th anniversary, Hyundai World Rally Team's amazing journeyHyundai Motor Group
 
Hot And Sexy 🥵 Call Girls Delhi Daryaganj {9711199171} Ira Malik High class G...
Hot And Sexy 🥵 Call Girls Delhi Daryaganj {9711199171} Ira Malik High class G...Hot And Sexy 🥵 Call Girls Delhi Daryaganj {9711199171} Ira Malik High class G...
Hot And Sexy 🥵 Call Girls Delhi Daryaganj {9711199171} Ira Malik High class G...shivangimorya083
 
Alina 7042364481 Call Girls Service Pochanpur Colony - independent Pochanpur ...
Alina 7042364481 Call Girls Service Pochanpur Colony - independent Pochanpur ...Alina 7042364481 Call Girls Service Pochanpur Colony - independent Pochanpur ...
Alina 7042364481 Call Girls Service Pochanpur Colony - independent Pochanpur ...Hot Call Girls In Sector 58 (Noida)
 
Call Girls in Malviya Nagar Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts Ser...
Call Girls in Malviya Nagar Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts Ser...Call Girls in Malviya Nagar Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts Ser...
Call Girls in Malviya Nagar Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts Ser...Delhi Call girls
 
꧁ ୨ Call Girls In Radisson Blu Plaza Delhi Airport, New Delhi ❀7042364481❀ Es...
꧁ ୨ Call Girls In Radisson Blu Plaza Delhi Airport, New Delhi ❀7042364481❀ Es...꧁ ୨ Call Girls In Radisson Blu Plaza Delhi Airport, New Delhi ❀7042364481❀ Es...
꧁ ୨ Call Girls In Radisson Blu Plaza Delhi Airport, New Delhi ❀7042364481❀ Es...Hot Call Girls In Sector 58 (Noida)
 
Russian Call Girls Delhi Indirapuram {9711199171} Aarvi Gupta ✌️Independent ...
Russian  Call Girls Delhi Indirapuram {9711199171} Aarvi Gupta ✌️Independent ...Russian  Call Girls Delhi Indirapuram {9711199171} Aarvi Gupta ✌️Independent ...
Russian Call Girls Delhi Indirapuram {9711199171} Aarvi Gupta ✌️Independent ...shivangimorya083
 
John Deere 7430 7530 Tractors Diagnostic Service Manual W.pdf
John Deere 7430 7530 Tractors Diagnostic Service Manual W.pdfJohn Deere 7430 7530 Tractors Diagnostic Service Manual W.pdf
John Deere 7430 7530 Tractors Diagnostic Service Manual W.pdfExcavator
 
Vip Hot🥵 Call Girls Delhi Delhi {9711199012} Avni Thakur 🧡😘 High Profile Girls
Vip Hot🥵 Call Girls Delhi Delhi {9711199012} Avni Thakur 🧡😘 High Profile GirlsVip Hot🥵 Call Girls Delhi Delhi {9711199012} Avni Thakur 🧡😘 High Profile Girls
Vip Hot🥵 Call Girls Delhi Delhi {9711199012} Avni Thakur 🧡😘 High Profile Girlsshivangimorya083
 
定制(Cantab毕业证书)剑桥大学毕业证成绩单原版一比一
定制(Cantab毕业证书)剑桥大学毕业证成绩单原版一比一定制(Cantab毕业证书)剑桥大学毕业证成绩单原版一比一
定制(Cantab毕业证书)剑桥大学毕业证成绩单原版一比一mjyguplun
 
Delhi Call Girls Mayur Vihar 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Mayur Vihar 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Mayur Vihar 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Mayur Vihar 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Callshivangimorya083
 
BLUE VEHICLES the kids picture show 2024
BLUE VEHICLES the kids picture show 2024BLUE VEHICLES the kids picture show 2024
BLUE VEHICLES the kids picture show 2024AHOhOops1
 
新南威尔士大学毕业证(UNSW毕业证)成绩单原版一比一
新南威尔士大学毕业证(UNSW毕业证)成绩单原版一比一新南威尔士大学毕业证(UNSW毕业证)成绩单原版一比一
新南威尔士大学毕业证(UNSW毕业证)成绩单原版一比一nsrmw5ykn
 
Dubai Call Girls Size E6 (O525547819) Call Girls In Dubai
Dubai Call Girls  Size E6 (O525547819) Call Girls In DubaiDubai Call Girls  Size E6 (O525547819) Call Girls In Dubai
Dubai Call Girls Size E6 (O525547819) Call Girls In Dubaikojalkojal131
 

Recently uploaded (20)

GREEN VEHICLES the kids picture show 2024
GREEN VEHICLES the kids picture show 2024GREEN VEHICLES the kids picture show 2024
GREEN VEHICLES the kids picture show 2024
 
How To Fix Mercedes Benz Anti-Theft Protection Activation Issue
How To Fix Mercedes Benz Anti-Theft Protection Activation IssueHow To Fix Mercedes Benz Anti-Theft Protection Activation Issue
How To Fix Mercedes Benz Anti-Theft Protection Activation Issue
 
Introduction of Basic of Paint Technology
Introduction of Basic of Paint TechnologyIntroduction of Basic of Paint Technology
Introduction of Basic of Paint Technology
 
Sales & Marketing Alignment_ How to Synergize for Success.pptx.pdf
Sales & Marketing Alignment_ How to Synergize for Success.pptx.pdfSales & Marketing Alignment_ How to Synergize for Success.pptx.pdf
Sales & Marketing Alignment_ How to Synergize for Success.pptx.pdf
 
加拿大温尼伯大学毕业证(UBC毕业证书)成绩单原版一比一
加拿大温尼伯大学毕业证(UBC毕业证书)成绩单原版一比一加拿大温尼伯大学毕业证(UBC毕业证书)成绩单原版一比一
加拿大温尼伯大学毕业证(UBC毕业证书)成绩单原版一比一
 
Delhi Call Girls East Of Kailash 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls East Of Kailash 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls East Of Kailash 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls East Of Kailash 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
 
如何办理爱尔兰都柏林大学毕业证(UCD毕业证) 成绩单原版一比一
如何办理爱尔兰都柏林大学毕业证(UCD毕业证) 成绩单原版一比一如何办理爱尔兰都柏林大学毕业证(UCD毕业证) 成绩单原版一比一
如何办理爱尔兰都柏林大学毕业证(UCD毕业证) 成绩单原版一比一
 
The 10th anniversary, Hyundai World Rally Team's amazing journey
The 10th anniversary, Hyundai World Rally Team's amazing journeyThe 10th anniversary, Hyundai World Rally Team's amazing journey
The 10th anniversary, Hyundai World Rally Team's amazing journey
 
Hot And Sexy 🥵 Call Girls Delhi Daryaganj {9711199171} Ira Malik High class G...
Hot And Sexy 🥵 Call Girls Delhi Daryaganj {9711199171} Ira Malik High class G...Hot And Sexy 🥵 Call Girls Delhi Daryaganj {9711199171} Ira Malik High class G...
Hot And Sexy 🥵 Call Girls Delhi Daryaganj {9711199171} Ira Malik High class G...
 
Alina 7042364481 Call Girls Service Pochanpur Colony - independent Pochanpur ...
Alina 7042364481 Call Girls Service Pochanpur Colony - independent Pochanpur ...Alina 7042364481 Call Girls Service Pochanpur Colony - independent Pochanpur ...
Alina 7042364481 Call Girls Service Pochanpur Colony - independent Pochanpur ...
 
Call Girls in Malviya Nagar Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts Ser...
Call Girls in Malviya Nagar Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts Ser...Call Girls in Malviya Nagar Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts Ser...
Call Girls in Malviya Nagar Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts Ser...
 
꧁ ୨ Call Girls In Radisson Blu Plaza Delhi Airport, New Delhi ❀7042364481❀ Es...
꧁ ୨ Call Girls In Radisson Blu Plaza Delhi Airport, New Delhi ❀7042364481❀ Es...꧁ ୨ Call Girls In Radisson Blu Plaza Delhi Airport, New Delhi ❀7042364481❀ Es...
꧁ ୨ Call Girls In Radisson Blu Plaza Delhi Airport, New Delhi ❀7042364481❀ Es...
 
Russian Call Girls Delhi Indirapuram {9711199171} Aarvi Gupta ✌️Independent ...
Russian  Call Girls Delhi Indirapuram {9711199171} Aarvi Gupta ✌️Independent ...Russian  Call Girls Delhi Indirapuram {9711199171} Aarvi Gupta ✌️Independent ...
Russian Call Girls Delhi Indirapuram {9711199171} Aarvi Gupta ✌️Independent ...
 
John Deere 7430 7530 Tractors Diagnostic Service Manual W.pdf
John Deere 7430 7530 Tractors Diagnostic Service Manual W.pdfJohn Deere 7430 7530 Tractors Diagnostic Service Manual W.pdf
John Deere 7430 7530 Tractors Diagnostic Service Manual W.pdf
 
Vip Hot🥵 Call Girls Delhi Delhi {9711199012} Avni Thakur 🧡😘 High Profile Girls
Vip Hot🥵 Call Girls Delhi Delhi {9711199012} Avni Thakur 🧡😘 High Profile GirlsVip Hot🥵 Call Girls Delhi Delhi {9711199012} Avni Thakur 🧡😘 High Profile Girls
Vip Hot🥵 Call Girls Delhi Delhi {9711199012} Avni Thakur 🧡😘 High Profile Girls
 
定制(Cantab毕业证书)剑桥大学毕业证成绩单原版一比一
定制(Cantab毕业证书)剑桥大学毕业证成绩单原版一比一定制(Cantab毕业证书)剑桥大学毕业证成绩单原版一比一
定制(Cantab毕业证书)剑桥大学毕业证成绩单原版一比一
 
Delhi Call Girls Mayur Vihar 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Mayur Vihar 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Mayur Vihar 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Mayur Vihar 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
 
BLUE VEHICLES the kids picture show 2024
BLUE VEHICLES the kids picture show 2024BLUE VEHICLES the kids picture show 2024
BLUE VEHICLES the kids picture show 2024
 
新南威尔士大学毕业证(UNSW毕业证)成绩单原版一比一
新南威尔士大学毕业证(UNSW毕业证)成绩单原版一比一新南威尔士大学毕业证(UNSW毕业证)成绩单原版一比一
新南威尔士大学毕业证(UNSW毕业证)成绩单原版一比一
 
Dubai Call Girls Size E6 (O525547819) Call Girls In Dubai
Dubai Call Girls  Size E6 (O525547819) Call Girls In DubaiDubai Call Girls  Size E6 (O525547819) Call Girls In Dubai
Dubai Call Girls Size E6 (O525547819) Call Girls In Dubai
 

Meta Programming C++ RPC

  • 2. www.luxoft.com Introduction Metaprogramming in C++ (Andrei Alexandrescu, 2002). Templates: • one of the most powerful part of C++ • quite new technology (just only 18 years old)
  • 4. www.luxoft.comwww.luxoft.com struct calc_interface { struct functions { double add(double, double); int eval(std::string); }; struct signals { void expr_evaluated(int, double); }; }; Interface definition: Ideal case
  • 5. www.luxoft.com Example of usage struct calc_server: server_t<calc_interface> { double add(double a, double b) override { return a + b; }; int eval(string expr) override { static int id(0); ++id; new std::thread( [this, expr, id] () { sleep(100); this->expr_evaluated(expr, 12345); } ); return id; } }; client_t<calc_interface> client; // subscribe to the signal .. client.expr_evaluated( [] (int id, string expr, double res) { cout << expr << "→" << res; } ); // execute functions .. cout << client.add(1,2) << endl; client.add(1,2, [] (double res) { cout << res << endl; })
  • 6. www.luxoft.comwww.luxoft.com struct calc_interface { RPC_FUNCTION(double(double, double), add); RPC_FUNCTION(int(std::string), eval); RPC_SIGNAL (void(int, double), expr_evaluated); }; Interface definition: implemented case
  • 7. www.luxoft.com Usage server_t<calc_interface> server(transpotr); server_t::initialize(server) .add_handler<calc_interface::add> ( [] (double a, double b) { return a + b;} ) .add_handler<calc_interface::eval> ( [] (string expr) → int { static int id(0); ++id; new std::thread( [this, expr, id] () { sleep(100); server.emit<expr_evaluated>(expr, 12345); } ); return id; }); client_t<calc_interface> client(transpotr); // subscribe to the signal .. client.subscribe<client_t::expr_evaluated>( [] (int id, string expr, double res) { cout << expr << "→" << res; } ); // execute functions .. cout << client.invoke<add>(1,2) << endl; // async invoke client.invoke(1,2, [] (double res) { cout << res << endl; })
  • 8. www.luxoft.com What should be taken into account • Wrong function parameters. e.g. the following should cause a compile time errors – client.invoke<add>(“hello” , 123) or client.invoke<add>(1) or client.invoke<add>(1, 2, 3) • Execution of nonexistent function – interface_1 { RPC_FN (void (int), fn1) }; – interface_2 { RPC_FN (void (double), fn2) }; – client_t<interface_1>().invoke<interface_2::fn2>(5.);
  • 9. www.luxoft.com Implementation struct calc_interface { // RPC_FUNCTION(double(double, double), add); struct add: meta_function_t<double (double, double), true> { static const char* uniq_name() { return “add”; } }; //RPC_FUNCTION(int(std::string), eval); struct eval: meta_function_t<double (double, double), true> { static const char* uniq_name() { return “eval”; }; //RPC_SIGNAL (void(int, double), expr_evaluated); struct expr_evaluated: meta_function_t<double (double, double), false> { static const char* uniq_name() { return “expr_evaluated”; }; }; meta_function_t < R (Arg0, …, ArgN) , bool> :: result_type → R; meta_function_t < R (Arg0, …, ArgN) , bool> :: args_count → N; meta_function_t < R (Arg0, …, ArgN) , bool> :: arg<0>::type → Arg0; ... meta_function_t < R (Arg0, …, ArgN) , bool> :: arg<N>::type → ArgN; meta_function_t < R (Arg0, …, ArgN) , bool> ::is_function → bool
  • 10. www.luxoft.comwww.luxoft.com namespace details { template<typename... Args> struct args_count { enum { value = 0 }; }; template<typename A1, typename ... Args> struct args_count<A1, Args...> { enum { value = 1 + args_count<Args...>::value }; };} cout << detail::args_count < >::value ; → 0 cout << detail::args_count < int >::value ; → 1 cout << detail::args_count < int , float>::value ; → 2
  • 11. www.luxoft.comwww.luxoft.com namepsace detail { template<unsigned int N, typename ...Args> struct arg; template<typename A0, typename ...Args> struct arg<0, A0, Args...> { typedef A0 type; }; template<unsigned int N, typename A0, typename ...Args> struct arg<N, A0, Args...> { typedef typename arg<N - 1, Args...>::type type; }; } detail::arg<0, int>::type → int detail::arg<0, int, double>::type → int detail::arg<1, int, double>::type → double
  • 12. www.luxoft.comwww.luxoft.com template<typename FnSygn, bool> struct meta_function; template<typename UniqType, bool isFn, typename R, typename ...Args> struct meta_function<R(Args…), isFn> { typedef R result_type; enum { args_count = detail::args_count<Args...>::value }; template<unsigned int N> struct arg { typedef typename detail::arg<N, Args...>::type type; }; enum { is_function = isFn }; };
  • 13. www.luxoft.com client.invoke // calc_interface struct add: meta_function_t<double (double, double), true> { … }; // client_t<calc_interface> client: … auto result = client.invoke<add> ( … ) : 1) check arguments 2) serialize arguments 3) serialize function ID 4) send data 5) wait for response 6) deserialize and return result
  • 14. www.luxoft.com client.invoke template< typename MetaFn, typename ...Args> typename MetaFn::result_type invoke ( Args const&... args) { check if <MetaFn> declared in <calc_interface> ; static_assert(MetaFn::is_function == true); static_assert(MetaFn::args_count == detail::args_count<Args...>::value); typename MetaFn::arg<0>::type a0 = get<0>(args...); ... typename MetaFn::arg<N>::type a1 = get<N>(args...); // ---->>> auto ostream = transport.get_ostream( ); ostream << MetaFn::uniq_name() << arg0 << … << argN; int sequence_id = transport.send(ostream); transport_wait_for_response(sequence_id); auto istream = transport.get_istream(sequence_id); MetaFn::result_type result; istream >> result; return result; }
  • 15. www.luxoft.com client.invoke template<typename MetaFn, unsigned int N, typename IStream, typename ...Args> void serrialize_all(IStream & , Args ...args) { }; template<typename MetaFn, unsigned int N, typename IStream, typename Arg0, typename ...Args> void serrialize_all(IStream & stream, Arg0 const& arg0,Args ...args) { typename typedef MetaFn::arg<N>::type arg_to_send = arg0; stream << arg0; serrialize_all<MetaFn, N + 1> (stream, args...); }
  • 16. www.luxoft.com client.invoke template< typename MetaFn, typename ...Args> typename MetaFn::result_type invoke ( Args const&... args ) { check if <MetaFn> declared in <calc_interface> ; static_assert(MetaFn::is_function == true); static_assert(MetaFn::args_count == detail::args_count<Args...>::value); auto ostream = transport.get_ostream( ); serrialize_all<MetaFn,0>(ostream, MetaFn::uniq_name(), args...); int sequence_id = transport.send(ostream); transport_wait_for_response(sequence_id); auto istream = transport.get_istream(sequence_id); MetaFn::result_type result; istream >> result; return result; }
  • 17. www.luxoft.com Exists or not ? struct calc_interface { long __registrate_meta_type(…); // RPC_FUNCTION(double(double, double), add); struct add: meta_function_t<double (double, double), true> { static const char* uniq_name() { return “add”; } }; char __registrate_meta_type(add ); ... char __registrate_meta_type(expr_evaluated); }; template< typename Interface, typename MetaFn> struct is_present { enum { value = sizeof( ((Interface*)0)→ __registrate_meta_type(MetaFn())) == 1 ? 1 : 0 }; }; std::cout << is_present<calc_interface, calc_interface::add>::value → 1 std::cout << is_present<calc_interface, calc_interface::eval>::value → 1 std::cout << is_present<calc_interface, int>::value → 0
  • 18. www.luxoft.com Client.invoke – final version //client_t<calc_interface> client; // template<Interface> client_t { typedef Interface interface; }; template< typename MetaFn, typename ...Args>0 typename MetaFn::result_type invoke( Args const&... args ) { static_assert(is_present<interface, MetaFn> :: value == 1); static_assert(MetaFn::is_function == true); static_assert(MetaFn::args_count == detail::args_count<Args...>::value); auto ostream = transport.get_ostream( ); serrialize_all<MetaFn,0>(ostream, MetaFn::uniq_name(), args...); int sequence_id = transport.send(ostream); transport_wait_for_response(sequence_id); auto istream = transport.get_istream(sequence_id); MetaFn::result_type result; istream >> result; return result; }