Skip to content

Commit

Permalink
decorator example
Browse files Browse the repository at this point in the history
  • Loading branch information
BerengerBerthoul committed Sep 14, 2023
1 parent 84a93ea commit 9ad2954
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
43 changes: 43 additions & 0 deletions examples/decorator.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include <tuple>
#include <iostream>
#include <utility>
#include <vector>
#include <array>
#include <iostream>
#include <memory>
#include <cassert>

#include "fmt/format.h"
#include "fmt/ranges.h"

// ---------------------------------------------------------------------------
template<typename F>
auto stars(F& func) {
return [func](auto&&... args) {
std::cout << "*******" << std::endl;
// Faire avec type de retour !!
func(std::forward<decltype(args)>(args)...);
std::cout << "\n*******" << std::endl;
};
}

// ---------------------------------------------------------------------------
void hello_impl() {
std::cout << "hello, world!";
}

// ---------------------------------------------------------------------------
int get_impl(int i) {
return i;
}
// ---------------------------------------------------------------------------
auto hello = stars(hello_impl);
auto super_get = stars(get_impl);

// ===========================================================================
int main(void)
{
hello();
// int ci = super_get(10);
// assert(ci == 10);
}
2 changes: 1 addition & 1 deletion external/project_utils

0 comments on commit 9ad2954

Please sign in to comment.