Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <type_traits>
- #include "func.h"
- void NoRefFoo(Counter x) {
- std::cout << "No ref func: " << x << '\n';
- }
- void RefFoo(const Counter& x) {
- std::cout << "Ref func: " << x << '\n';
- }
- class ReproducibleRNG {
- private:
- unsigned long seed_;
- public:
- ReproducibleRNG(unsigned long seed = 1) : seed_(seed) {}
- void set_seed(unsigned long seed) { seed_ = seed; }
- long operator()() {
- seed_ = (seed_ * 1103515245 + 12345) & 0x7FFFFFFF;
- return seed_;
- }
- long operator()(long min, long max) {
- return min + (operator()() % (max - min + 1));
- }
- };
- int main() {
- static_assert(sizeof(Counter) <= 8);
- int x = 0;
- Counter w(x);
- int n; std::cin >> n;
- ReproducibleRNG rnd(n);
- static_assert(!std::is_invocable_v<decltype(NoRefFoo), Counter>);
- static_assert(std::is_invocable_v<decltype(RefFoo), Counter>);
- static_assert(std::is_invocable_v<decltype(RefFoo), const Counter&>);
- std::cout << "All static assertions passed!\n";
- RefFoo(w);
- x = 19;
- int cnt;
- do {
- cnt = rnd(1, 20);
- } while(cnt == 0);
- for (size_t i = 0; i < cnt; ++i) {
- std::cout << w << '\n';
- }
- std::cout << w << '\n';
- x = 38;
- std::cout << w << '\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment