Simplified distributed block storage with strong consistency, like in Ceph
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

52 lines
1.1 KiB

  1. // Copyright (c) Vitaliy Filippov, 2019+
  2. // License: VNPL-1.0 (see README.md for details)
  3. #include <iostream>
  4. #include <functional>
  5. #include <array>
  6. #include <cstdlib> // for malloc() and free()
  7. using namespace std;
  8. // replace operator new and delete to log allocations
  9. void* operator new(std::size_t n)
  10. {
  11. cout << "Allocating " << n << " bytes" << endl;
  12. return malloc(n);
  13. }
  14. void operator delete(void* p) throw()
  15. {
  16. free(p);
  17. }
  18. class test
  19. {
  20. public:
  21. std::string s;
  22. void a(std::function<void()> & f, const char *str)
  23. {
  24. auto l = [this, str]() { cout << str << " ? " << s << " from this\n"; };
  25. cout << "Assigning lambda3 of size " << sizeof(l) << endl;
  26. f = l;
  27. }
  28. };
  29. int main()
  30. {
  31. std::array<char, 16> arr1;
  32. auto lambda1 = [arr1](){};
  33. cout << "Assigning lambda1 of size " << sizeof(lambda1) << endl;
  34. std::function<void()> f1 = lambda1;
  35. std::array<char, 17> arr2;
  36. auto lambda2 = [arr2](){};
  37. cout << "Assigning lambda2 of size " << sizeof(lambda2) << endl;
  38. std::function<void()> f2 = lambda2;
  39. test t;
  40. std::function<void()> f3;
  41. t.s = "str";
  42. t.a(f3, "huyambda");
  43. f3();
  44. }