Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // sudo apt-get install libboost-all-dev
- // g++ prog.cc -Wall -Wextra -I/opt/wandbox/boost-1.73.0/gcc-head/include -std=c++2b
- // clang++ prog.cc -Wall -Wextra -I/opt/wandbox/boost-1.69.0/clang-7.0.0/include -std=c++11
- //
- #include <iostream>
- #include <string>
- #define BOOST // #define SPROUT
- #if defined(BOOST)
- #include <boost/optional.hpp> // boost 1.63.0
- #include <cstdlib>
- #include <boost/timer/timer.hpp>
- #elif defined(SPROUT)
- #include <sprout/optional.hpp> // sprout not boost
- #endif
- #if defined(BOOST)
- boost::optional<int> f(int n)
- {
- return { n };
- }
- #elif defined(SPROUT)
- sprout::optional<int> f(int n)
- {
- return { n };
- }
- #endif
- int main()
- {
- #if defined(BOOST)
- const auto n1 = f(23);
- if (n1) std::cout << "note its a pointer " << *n1 << std::endl;
- const long n=10000000;
- {
- boost::timer::cpu_timer timer;
- for (long i = 0; i < n; ++i) {
- // DO 1
- }
- std::string result = timer.format();
- std::cout << result << std::endl;
- }
- {
- boost::timer::cpu_timer timer;
- for (long i = 0; i < n; ++i) {
- // DO 2
- }
- std::string result = timer.format();
- std::cout << result << std::endl;
- }
- #elif defined(SPROUT)
- const auto n = f(23);
- for (int i : n) std::cout << "the value using sprout " << i << std::endl;
- #endif
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement