text:
// Re-used parts from BOOST sorting benchmark suite

#include <algorithm>
#include <iostream>
#include <iomanip>
#include <random>
#include <stdlib.h>
#include <vector>

#include <boost/sort/common/time_measure.hpp>
#include <boost/sort/common/file_vector.hpp>
#include "boost/sort/common/int_array.hpp"

#include <boost/sort/sort.hpp>

#ifndef NO_LLVM
extern "C" {
  #include "introsort.h"
}
#endif

using namespace std;
namespace bsort = boost::sort;
namespace bsc = boost::sort::common;

using bsc::time_point;
using bsc::now;
using bsc::subtract_time;
using bsc::fill_vector_uint64;
using bsc::write_file_uint64;

template<typename A> double time_op(A op) {
  auto start = now ();
  op();
  auto finish = now ();
  return subtract_time (finish, start);
}

template<typename A> void time_op(std::string name, A op) {
  auto start = now ();
  op();
  auto finish = now ();
  auto duration = subtract_time (finish, start);

  std::cout<<"  "<<name<<"."<<"time: "<<duration<<std::endl;
}

template<class IA, class compare>
void test_sorted(std::vector<IA> &A, compare comp)
{
  if (!std::is_sorted(A.begin (), A.end (), comp)) {
    std::cout<<"*** NOT SORTED *** "<<std::endl;
  }
}

template<class IA, class compare, class Op>
void sort_test(std::vector<IA> &A, std::vector<IA> &B, size_t NITER, compare comp, Op op, bool verify=true) {
//   std::cout<<name<<std::endl;

  vector<double> durations;

  for (size_t i=0;i<NITER;++i) {
    A=B;

    durations.push_back(time_op(op) * 1000.0);
    if (verify) test_sorted(A,comp);
  }

  std::sort(durations.begin(),durations.end());

  auto N=durations.size();
//   auto l=durations.begin()+N/10;
//   auto h=durations.end()-N/10;
  auto l=durations.begin();
  auto h=durations.end();

  N=h-l;

  double duration=std::accumulate(l,h,0.0) / (double)N;
  double min=*std::min_element(l,h);
  double max=*std::max_element(l,h);
//   double dev=max-min;

  std::cout<<": "<<std::setw(2)<<duration<<" ["<<min<<" .. "<<max<<"] ";

  for (auto i=l;i!=h;++i)
      std::cout<<std::setw(2)<<*i<<" ";

  std::cout<<std::endl;
}

class Int_Generator {
public:

  static vector<uint64_t> random(size_t NELEM) {
    vector<uint64_t> A;
    A.reserve (NELEM);
    A.clear ();
    if (fill_vector_uint64 ("input.bin", A, NELEM) != 0)
    {
        std::cout << "Error in the input file\n";
        exit(1);
    };
    return A;
  }

  static vector<uint64_t> random_dup (size_t NELEM, size_t nvals)
  {
    vector<uint64_t> A;
    A.reserve (NELEM);
    A.clear ();
    if (fill_vector_uint64 ("input.bin", A, NELEM) != 0)
    {
        std::cout << "Error in the input file\n";
        exit(1);
    };

    for (size_t i=0;i<A.size();++i) A[i]%=nvals;

    return A;
  }

  static vector<uint64_t> sorted (size_t NELEM)
  {
    vector<uint64_t> A;

    A.reserve (NELEM);
    A.clear ();
    for (size_t i = 0; i < NELEM; ++i)
        A.push_back (i);

    return A;
  }

  static vector<uint64_t> organ_pipe (size_t NELEM)
  {
    vector<uint64_t> A;

    A.reserve (NELEM);
    A.clear ();

    size_t n = NELEM/2;
    uint64_t v=0;

    for (size_t i=0;i<n;++i) A.push_back(v++);
    for (size_t i=n;i<2*n;++i) A.push_back(--v);
    return A;
  }

  static vector<uint64_t> almost_sorted (size_t NELEM, size_t nperm)
  {
    vector<uint64_t> A;

    A.reserve (NELEM);
    A.clear ();
    for (size_t i = 0; i < NELEM; ++i)
        A.push_back (i);

    vector<size_t> P;

    if (fill_vector_uint64 ("input.bin", P, 2*nperm) != 0)
    {
        std::cout << "Error in the input file\n";
        exit(1);
    };

    for (size_t i=0;i<P.size();++i) P[i]%=NELEM;

    for (size_t i=0;i+1<P.size();i+=2) {
      std::swap(A[P[i]],A[P[i+1]]);
    }

    return A;
  }

  static vector<uint64_t> alleq (size_t NELEM)
  {
    vector<uint64_t> A(NELEM,42);
    return A;
  }

  static vector<uint64_t> sorted_end (size_t NELEM,size_t n_last)
  {
    vector<uint64_t> A;
    A.reserve (NELEM);
    A.clear ();
    if (fill_vector_uint64 ("input.bin", A, NELEM + n_last) != 0)
    {
        std::cout << "Error in the input file\n";
        exit(1);
    };
    std::sort (A.begin (), A.begin () + NELEM);

    return A;
  }

  static vector<uint64_t> sorted_middle (size_t NELEM, size_t n_last)
  {
    vector<uint64_t> A, B, C;
    A.reserve (NELEM);
    A.clear ();
    if (fill_vector_uint64 ("input.bin", A, NELEM + n_last) != 0)
    {
        std::cout << "Error in the input file\n";
        exit(1);
    };
    for (size_t i = NELEM; i < A.size (); ++i)
        B.push_back (std::move (A[i]));
    A.resize ( NELEM);
    for (size_t i = 0; i < (NELEM >> 1); ++i)
        std::swap (A[i], A[NELEM - 1 - i]);

    std::sort (A.begin (), A.end ());
    size_t step = NELEM / n_last + 1;
    size_t pos = 0;

    for (size_t i = 0; i < B.size (); ++i, pos += step)
    {
        C.push_back (B[i]);
        for (size_t k = 0; k < step; ++k)
            C.push_back (A[pos + k]);
    };
    while (pos < A.size ())
        C.push_back (A[pos++]);
    A = C;
    return A;
  }

  static vector<uint64_t> reverse_sorted (size_t NELEM)
  {
    vector<uint64_t> A;

    A.reserve (NELEM);
    A.clear ();
    for (size_t i = NELEM; i > 0; --i)
        A.push_back (i);

    return A;
  }

  static vector<uint64_t> reverse_sorted_end (size_t NELEM, size_t n_last)
  {
    vector<uint64_t> A;
    A.reserve (NELEM);
    A.clear ();
    if (fill_vector_uint64 ("input.bin", A, NELEM + n_last) != 0)
    {
        std::cout << "Error in the input file\n";
        exit(1);
    };
    std::sort (A.begin (), A.begin () + NELEM);
    for (size_t i = 0; i < (NELEM >> 1); ++i)
        std::swap (A[i], A[NELEM - 1 - i]);

    return A;
  }

  static vector<uint64_t> reverse_sorted_middle (size_t NELEM, size_t n_last)
  {
    vector<uint64_t> A, B, C;
    A.reserve (NELEM);
    A.clear ();
    if (fill_vector_uint64 ("input.bin", A, NELEM + n_last) != 0)
    {
        std::cout << "Error in the input file\n";
        exit(1);
    };
    for (size_t i = NELEM; i < A.size (); ++i)
        B.push_back (std::move (A[i]));
    A.resize ( NELEM);
    for (size_t i = 0; i < (NELEM >> 1); ++i)
        std::swap (A[i], A[NELEM - 1 - i]);

    std::sort (A.begin (), A.end ());
    size_t step = NELEM / n_last + 1;
    size_t pos = 0;

    for (size_t i = 0; i < B.size (); ++i, pos += step)
    {
        C.push_back (B[i]);
        for (size_t k = 0; k < step; ++k)
            C.push_back (A[pos + k]);
    };
    while (pos < A.size ())
        C.push_back (A[pos++]);
    A = C;
    return A;
  };

  static void stats(vector<uint64_t> &A) {
    auto B=A;

    // Count different values, min,max,avg length of strings
    std::sort(B.begin(),B.end());
    auto i = std::unique(B.begin(),B.end());
    size_t n = i-B.begin();

    cout<<"# "<<A.size()<<" numbers "<<n<<" different"<<endl;
  }

public:
  static vector<uint64_t> generate_aux(size_t NELEM, string name) {
    if (name=="random") return random(NELEM);
    else if (name=="random-dup-10") return random_dup(NELEM,NELEM/10);
    else if (name=="random-boolean") return random_dup(NELEM,2);
    else if (name=="organ-pipe") return organ_pipe(NELEM);
    else if (name=="sorted") return sorted(NELEM);
    else if (name=="equal") return alleq(NELEM);
    else if (name=="almost-sorted-.1") return almost_sorted(NELEM,NELEM/1000);
    else if (name=="almost-sorted-1") return almost_sorted(NELEM,NELEM/100);
    else if (name=="almost-sorted-10") return almost_sorted(NELEM,NELEM/10);
    else if (name=="almost-sorted-50") return almost_sorted(NELEM,NELEM/2);
    else if (name=="sorted-end-.1") return sorted_end(NELEM,NELEM/1000);
    else if (name=="sorted-end-1") return sorted_end(NELEM,NELEM/100);
    else if (name=="sorted-end-10") return sorted_end(NELEM,NELEM/10);
    else if (name=="sorted-middle-.1") return sorted_middle(NELEM,NELEM/1000);
    else if (name=="sorted-middle-1") return sorted_middle(NELEM,NELEM/100);
    else if (name=="sorted-middle-10") return sorted_middle(NELEM,NELEM/10);
    else if (name=="rev-sorted") return reverse_sorted(NELEM);
    else if (name=="rev-sorted-end-.1") return reverse_sorted_end(NELEM,NELEM/1000);
    else if (name=="rev-sorted-end-1") return reverse_sorted_end(NELEM,NELEM/100);
    else if (name=="rev-sorted-end-10") return reverse_sorted_end(NELEM,NELEM/10);
    else if (name=="rev-sorted-middle-.1") return reverse_sorted_middle(NELEM,NELEM/1000);
    else if (name=="rev-sorted-middle-1") return reverse_sorted_middle(NELEM,NELEM/100);
    else if (name=="rev-sorted-middle-10") return reverse_sorted_middle(NELEM,NELEM/10);

    else {
      cout<<"No such integer generator "<<name<<endl;
      exit(1);
    }
  }

  static vector<uint64_t> generate(size_t NELEM, string name) {
    auto A = generate_aux(NELEM,name);
    stats(A);
    return A;
  }

};

#ifndef NO_LLVM

llstring cnv_str(string s) {
  llstring res;
  str_init(&res);

  for (auto c = s.begin(); c!=s.end();++c) { str_append(&res,*c); }
  return res;
}

std::vector<llstring> cnv_strvec(std::vector<string> v) {
  std::vector<llstring> res;
  res.reserve(v.size());

  for (auto i = v.begin();i!=v.end();++i) res.push_back(cnv_str(*i));

  return res;
}

string bcnv_str(const llstring &s) {
  string res="";

  for (size_t i=0;i<s.size;++i) { res = res + ((s.data[i])); }
  return res;
}

std::vector<string> bcnv_strvec(std::vector<llstring> v) {
  std::vector<string> res;
  res.reserve(v.size());

  for (auto i = v.begin();i!=v.end();++i) res.push_back(bcnv_str(*i));

  return res;
}

class String_Generator {

  static vector<string> random(size_t NELEM)
  {
    std::vector<std::string> A;
    A.reserve(NELEM);
    A.clear();
    if (bsc::fill_vector_string("input.bin", A, NELEM) != 0)
    {
      std::cout << "Error in the input file\n";
      exit(1);
    };
    return A;

  }

  static vector<string> sorted(size_t NELEM)
  {
    std::vector<std::string> A;
    A.reserve(NELEM);
    A.clear();
    if (bsc::fill_vector_string("input.bin", A, NELEM) != 0)
    {
      std::cout << "Error in the input file\n";
      exit(1);
    };
    std::sort( A.begin() , A.end() );
    return A;
  };

  static vector<string> almost_sorted (size_t NELEM, size_t nperm)
  {
    vector<string> A = sorted(NELEM);
    vector<size_t> P;

    if (fill_vector_uint64 ("input.bin", P, 2*nperm) != 0)
    {
        std::cout << "Error in the input file\n";
        exit(1);
    };

    for (size_t i=0;i<P.size();++i) P[i]%=NELEM;

    for (size_t i=0;i+1<P.size();i+=2) {
      std::swap(A[P[i]],A[P[i+1]]);
    }

    return A;
  }

  static vector<string> organ_pipe(size_t NELEM)
  {
    std::vector<std::string> A = sorted(NELEM);
    auto i = std::unique( A.begin() , A.end() );
    A.resize(i-A.begin());

    if (A.size()<NELEM/2) {
      std::cout << "Too many equal strings for organ-pipe distribution\n";
      exit(1);
    }
    A.resize(NELEM/2);
    A.insert(A.end(),A.begin(),A.end());
    std::reverse(A.begin()+NELEM/2,A.end());

    return A;
  };

  static vector<string> random_dup(size_t NELEM, size_t nval)
  {
    std::vector<std::string> D = sorted(nval);
    std::vector<size_t> S = Int_Generator::random_dup(NELEM,nval);

    std::vector<std::string> A;
    A.reserve(NELEM);
    A.clear();
    for (size_t i=0;i<NELEM;++i) {
      A.push_back(D[S[i]]);
    }

    return A;
  };

  static vector<string> alleq(size_t NELEM)
  {
    std::vector<std::string> D = sorted(1);

    std::vector<std::string> A;
    A.reserve(NELEM);
    A.clear();
    for (size_t i=0;i<NELEM;++i) {
      A.push_back(D[0]);
    }

    return A;
  };

  static vector<string> sorted_end(size_t NELEM, size_t n_last)
  {
    std::vector<std::string> A;
    A.reserve(NELEM);
    A.clear();
    if (bsc::fill_vector_string("input.bin", A, NELEM+ n_last) != 0)
    {
      std::cout << "Error in the input file\n";
      exit(1);
    };
    std::sort (A.begin() , A.begin() + NELEM );
    return A;
  };

  static vector<string> sorted_middle(size_t NELEM,size_t n_last)
  {
    std::vector<std::string> A,B,C;
    A.reserve(NELEM);
    A.clear();
    if (bsc::fill_vector_string("input.bin", A, NELEM + n_last) != 0)
    {
      std::cout << "Error in the input file\n";
      exit(1);
    };
    for ( size_t i = NELEM; i < A.size() ; ++i)
      B.push_back ( std::move ( A[i]));
    A.resize ( NELEM);
    std::sort (A.begin() , A.end() );
    size_t step = NELEM/n_last +1 ;
    size_t pos = 0 ;

    for ( size_t i =0 ; i < B.size() ; ++i, pos += step)
    {   C.push_back ( B[i]);
      for ( size_t k = 0 ; k < step ; ++k )
        C.push_back ( A[pos + k] );
    };
    while ( pos < A.size() ) C.push_back ( A[pos++]);
    A = C ;

    return A;
  };

  static vector<string> reverse_sorted(size_t NELEM)
  {

    std::vector<std::string> A;
    A.reserve(NELEM);
    {
      std::vector<std::string> B;
      B.reserve(NELEM);
      if (bsc::fill_vector_string("input.bin", B, NELEM) != 0)
      {
        std::cout << "Error in the input file\n";
        exit(1);
      };
      std::sort(B.begin(), B.end());
      A.clear();
      for (size_t i = 0; i < NELEM; ++i)
        A.push_back(B[NELEM - 1 - i]);
    };
    return A;
  };

  static vector<string> reverse_sorted_end(size_t NELEM,size_t n_last)
  {
    std::vector<std::string> A;
    A.reserve(NELEM);
    A.clear();
    if (bsc::fill_vector_string("input.bin", A, NELEM+ n_last) != 0)
    {
      std::cout << "Error in the input file\n";
      exit(1);
    };
    std::sort (A.begin() , A.begin() + NELEM );
    for ( size_t i =0 ; i< (NELEM >>1); ++i)
      std::swap ( A[i], A[NELEM - 1 - i]);

    return A;

  };

  static vector<string> reverse_sorted_middle(size_t NELEM,size_t n_last)
  {
    std::vector<std::string> A,B,C;
    A.reserve(NELEM);
    A.clear();
    if (bsc::fill_vector_string("input.bin", A, NELEM + n_last) != 0)
    {
      std::cout << "Error in the input file\n";
      exit(1);
    };
    for ( size_t i = NELEM ; i < A.size() ; ++i)
      B.push_back ( std::move ( A[i]));
    A.resize ( NELEM);

    std::sort (A.begin() , A.end() );
    for ( size_t i =0 ; i< (NELEM >>1); ++i)
      std::swap ( A[i], A[NELEM - 1 - i]);

    size_t step = NELEM /n_last +1 ;
    size_t pos = 0 ;

    for ( size_t i =0 ; i < B.size() ; ++i, pos += step)
    {   C.push_back ( B[i]);
      for ( size_t k = 0 ; k < step ; ++k )
        C.push_back ( A[pos + k] );
    };
    while ( pos < A.size() )
      C.push_back ( A[pos++]);
    A = C ;

    return A;
  };

public:

  static void stats(vector<string> &A) {
    auto B=A;

    // Sum up all string length
    size_t suml=0;
    for (auto i=B.begin();i<B.end();++i) suml+=i->size();

    // Count different values, min,max,avg length of strings
    std::sort(B.begin(),B.end());
    auto i = std::unique(B.begin(),B.end());
    B.resize(i-B.begin());

    size_t minl = B[0].size(),maxl = B[0].size();

    for (auto i=B.begin()+1;i!=B.end();++i) {
      minl=min(minl,i->size());
      maxl=max(maxl,i->size());
    }

    cout<<"# "<<A.size()<<" strings "<<B.size()<<" different. Lengths ["<<minl<<".."<<maxl<<"] avg: "<<suml/A.size()<<endl;
  }

  static vector<string> generate_aux(size_t NELEM, string name) {
    if (name=="random") return random(NELEM);
    else if (name=="random-dup-10") return random_dup(NELEM,NELEM/10);
    else if (name=="random-boolean") return random_dup(NELEM,2);
    else if (name=="organ-pipe") return organ_pipe(NELEM);
    else if (name=="sorted") return sorted(NELEM);
    else if (name=="equal") return alleq(NELEM);
    else if (name=="almost-sorted-.1") return almost_sorted(NELEM,NELEM/1000);
    else if (name=="almost-sorted-1") return almost_sorted(NELEM,NELEM/100);
    else if (name=="almost-sorted-10") return almost_sorted(NELEM,NELEM/10);
    else if (name=="almost-sorted-50") return almost_sorted(NELEM,NELEM/2);
    else if (name=="sorted-end-.1") return sorted_end(NELEM,NELEM/1000);
    else if (name=="sorted-end-1") return sorted_end(NELEM,NELEM/100);
    else if (name=="sorted-end-10") return sorted_end(NELEM,NELEM/10);
    else if (name=="sorted-middle-.1") return sorted_middle(NELEM,NELEM/1000);
    else if (name=="sorted-middle-1") return sorted_middle(NELEM,NELEM/100);
    else if (name=="sorted-middle-10") return sorted_middle(NELEM,NELEM/10);
    else if (name=="rev-sorted") return reverse_sorted(NELEM);
    else if (name=="rev-sorted-end-.1") return reverse_sorted_end(NELEM,NELEM/1000);
    else if (name=="rev-sorted-end-1") return reverse_sorted_end(NELEM,NELEM/100);
    else if (name=="rev-sorted-end-10") return reverse_sorted_end(NELEM,NELEM/10);
    else if (name=="rev-sorted-middle-.1") return reverse_sorted_middle(NELEM,NELEM/1000);
    else if (name=="rev-sorted-middle-1") return reverse_sorted_middle(NELEM,NELEM/100);
    else if (name=="rev-sorted-middle-10") return reverse_sorted_middle(NELEM,NELEM/10);

    else {
      cout<<"No such string generator "<<name<<endl;
      exit(1);
    }
  }

  static vector<llstring> generate(size_t NELEM, string name) {
    auto A = generate_aux(NELEM,name);
    stats(A);
    return cnv_strvec(A);
  }

};

namespace std {
template<>
struct less<llstring>
{
   inline bool operator()(const llstring& k1, const llstring& k2) const
   {
//       return less<string>()(bcnv_str(k1), bcnv_str(k2));
     return llstrcmp((llstring*)&k1,(llstring*)&k2);
   }
};
}

#endif

// Disable branch-prediction optimization for all iterators, to make it comparable with our impl!
template<class Iter, class Compare>
inline void boost_pdqsort(Iter first, Iter last, Compare comp) {
    if (first == last) return;
    boost::sort::pdqsort_detail::pdqsort_loop<Iter, Compare, false >( first, last, comp, boost::sort::pdqsort_detail::log2(last - first));
}

template<class Iter>
inline void boost_pdqsort(Iter first, Iter last) {
    typedef typename std::iterator_traits<Iter>::value_type T;
    boost_pdqsort(first, last, std::less<T>());
}

void test_uint(string name, size_t NITER, vector<uint64_t> B) {
  std::vector<uint64_t> A (B);

  auto comp = std::less<uint64_t>();
#ifndef NO_LLVM
  if (name=="isabelle::sort") sort_test(A,B,NITER,comp,[&]{ introsort(A.data (), 0, A.size());});
  else if (name=="isabelle::pdqsort") sort_test(A,B,NITER,comp,[&]{ pdqsort(A.data (), 0, A.size());});
  else
#endif
  if (name=="std::sort") sort_test(A,B,NITER,comp,[&]{ std::sort(A.begin (), A.end (), comp);});
  else if (name=="boost::pdqsort") sort_test(A,B,NITER,comp,[&]{ boost_pdqsort(A.begin (), A.end (), comp);});
  else if (name=="boost::pdqsort_bp") sort_test(A,B,NITER,comp,[&]{ boost::sort::pdqsort(A.begin (), A.end ());});
  else if (name=="boost::sample_sort") sort_test(A,B,NITER,comp,[&]{ boost::sort::sample_sort(A.begin (), A.end (), comp, 12);});
  else {
    cout<<"No such sorting algorithm "<<name<<endl;
    exit(1);
  }
}

#ifndef NO_LLVM
void test_llstring(string name, size_t NITER, vector<llstring> &B) {
  std::vector<llstring> A (B);

  auto comp = std::less<llstring>();

  if (name=="isabelle::sort") sort_test(A,B,NITER,comp,[&]{ str_introsort(A.data (), 0, A.size());});
  else if (name=="isabelle::pdqsort") sort_test(A,B,NITER,comp,[&]{ str_pdqsort(A.data (), 0, A.size());});
  else if (name=="boost::pdqsort") sort_test(A,B,NITER,comp,[&]{ boost_pdqsort(A.begin (), A.end (), comp);});
  else if (name=="std::sort") sort_test(A,B,NITER,comp,[&]{ std::sort(A.begin (), A.end (), comp);});
  else if (name=="boost::sample_sort") sort_test(A,B,NITER,comp,[&]{ boost::sort::sample_sort(A.begin (), A.end (), comp, 12);});
  else {
    cout<<"No such sorting algorithm "<<name<<endl;
    exit(1);
  }
}
#endif

int main(int argc, char** argv) {

  if (argc != 6) {
    cout<<"Usage: do_benchmark type algo-name data-name NELEM NITER"<<endl;
    exit(1);
  }

  string type_name=argv[1];
  string algo_name=argv[2];
  string data_name=argv[3];
  size_t NELEM=stoul(argv[4]);
  size_t NITER=stoul(argv[5]);

  if (type_name == "uint64") {
    auto A = Int_Generator::generate(NELEM,data_name);
#ifdef NO_LLVM
    cout<<"NO_LLVM ";
#endif
    cout<<type_name<<" "<<algo_name<<" "<<data_name<<" "<<NELEM<<"x"<<NITER<<std::flush;
    test_uint(algo_name,NITER,A);
#ifndef NO_LLVM
  } else if (type_name == "llstring") {
    auto A = String_Generator::generate(NELEM,data_name);
    cout<<type_name<<" "<<algo_name<<" "<<data_name<<" "<<NELEM<<"x"<<NITER<<std::flush;
    test_llstring(algo_name,NITER,A);
#endif
  } else {
    cout<<"No such data type "<<type_name<<endl;
    exit(1);
  }

  return 0;
}


text:
// Copyright 2017 The BerryDB Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <iomanip>  // std::setw, std::setfill
#include <iostream>  // std::cout
#include <map>  // std::map
#include <vector>  // std::vector

#include <boost/tokenizer.hpp>  // boost::tokenizer, boost::escaped_list_separator

#if defined(BOOST_NO_EXCEPTIONS)

// We must define boost::throw_exception, because we disabled exceptions in the
// compiler.
// https://stackoverflow.com/questions/9272648/boost-symbol-not-found
namespace boost {
void throw_exception(const std::exception &) {
}
} // namespace boost

#endif  // defined(BOOST_NO_EXCEPTIONS)

void welcome() {
  const char * logo =
    " ______   ______   ______   ______   __  __   _____    ______    \n"
    "/\\  == \\ /\\  ___\\ /\\  == \\ /\\  == \\ /\\ \\_\\ \\ /\\  __-. /\\  == \\   \n"
    "\\ \\  __< \\ \\  __\\ \\ \\  __< \\ \\  __< \\ \\____ \\\\ \\ \\/\\ \\\\ \\  __<   \n"
    " \\ \\_____\\\\ \\_____\\\\ \\_\\ \\_\\\\ \\_\\ \\_\\\\/\\_____\\\\ \\____- \\ \\_____\\ \n"
    "  \\/_____/ \\/_____/ \\/_/ /_/ \\/_/ /_/ \\/_____/ \\/____/  \\/_____/ \n";
  std::cout << logo << std::endl;
  std::cout << "Welcome to BerryDB!" << std::endl;
}

void print_prompt(int line) {
  std::cout << "berrydb 🍓 :" << std::setw(3) << std::setfill('0') << line << "> ";
}

void print_output(std::string message) {
  std::cout << "=> " << message << std::endl;
}

typedef boost::tokenizer<boost::escaped_list_separator<char>> cli_tokenizer;

int main() {
  welcome();

  std::map<std::string, std::string> data;

  int line = 0;
  while (true) {
    print_prompt(++line);

    std::string input;
    std::getline(std::cin, input);

    std::string delimiter = " ";
    std::vector<std::string> args;
    cli_tokenizer tokenizer(input, boost::escaped_list_separator<char>('\\', ' ', '\"'));
    for (cli_tokenizer::iterator it = tokenizer.begin(); it != tokenizer.end(); ++it) {
      args.push_back(*it);
    }

    if (args.size() == 0) { continue; }
    if (args[0] == "get") {
      if (args.size() != 2) {
        print_output("⚠  Expected 1 argument.");
      } else {
        auto result = data.find(args[1]);
        if (result != data.end()) {
          print_output(result->second);
        } else {
          print_output("❌  Not found.");
        }
      }
    } else if (args[0] == "set") {
      if (args.size() != 3) {
        print_output("⚠  Expected 2 arguments.");
      } else {
        data[args[1]] = args[2];
      }
    } else if (args[0] == "delete") {
      if (args.size() != 2) {
        print_output("⚠  Expected 1 argument.");
      } else {
        auto result = data.find(args[1]);
        if (result != data.end()) {
          data.erase(args[1]);
        } else {
          print_output("❌  Not found.");
        }
      }
    } else {
      print_output("⚠  Unsupported command.");
    }
  }
  return 0;
}

ext: cc

max_stars_repo_name: AngleNet/berrydb

max_issues_repo_name: AngleNet/berrydb

max_forks_repo_name: AngleNet/berrydb


text:
// Copyright (c) 2020 Barath Kannan
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file license.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#define BOOST_TEST_MODULE StaticFunction

#include <boost/test/unit_test.hpp>

ext: cpp

max_stars_repo_name: Barath-Kannan/erasure

max_issues_repo_name: Barath-Kannan/erasure

max_forks_repo_name: Barath-Kannan/erasure


text:
#ifndef TEST_UTILS_HPP
#define TEST_UTILS_HPP

#include <boost/graph/edge_list.hpp>
#include <boost/graph/graph_concepts.hpp>
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/properties.hpp>

#include <kspwlo_ref/algorithms/kspwlo.hpp>

#include <arlib/path.hpp>
#include <arlib/type_traits.hpp>

#include <string_view>
#include <vector>

//===----------------------------------------------------------------------===//
//                      Utility functions for testing
//===----------------------------------------------------------------------===//

template <typename Graph>
bool one_regression_path_have_edges(std::vector<Path> &res_regression,
                                    Graph &G) {
  using boost::edges;
  using boost::source;
  using boost::target;
  auto first = edges(G).first;
  auto last = edges(G).second;

  bool has_them = false;
  for (auto &regr_path : res_regression) {
    int edges_count = 0;
    int nb_edges_regr_path_has = 0;
    for (auto it = first; it != last; ++it) {
      ++edges_count;
      NodeID u = source(*it, G);
      NodeID v = target(*it, G);

      if (regr_path.containsEdge(std::make_pair(u, v))) {
        ++nb_edges_regr_path_has;
      }
    }
    if (edges_count == nb_edges_regr_path_has) {
      has_them = true;
      break;
    }
  }
  return has_them;
}

template <typename Graph>
std::vector<arlib::edge_of_t<Graph>>
make_edge_list(arlib::Path<Graph> const &alt_path) {
  using namespace boost;
  auto res = std::vector<arlib::edge_of_t<Graph>>{};
  for (auto [first, last] = edges(alt_path); first != last; ++first) {
    res.push_back(*first);
  }
  return res;
}

template <typename Graph, typename WeightMap>
bool alternative_paths_are_dissimilar(
    std::vector<arlib::Path<Graph>> const &alt_paths, WeightMap const &weight,
    double theta) {
  // Build edge lists
  using Edge = arlib::edge_of_t<Graph>;
  auto edge_lists = std::vector<std::vector<Edge>>{};
  for (auto const &path : alt_paths) {
    edge_lists.push_back(make_edge_list(path));
  }

  // For each path_i, check its similarity with all the other paths.
  for (std::size_t i = 0; i < alt_paths.size(); ++i) {
    auto const &path_i = alt_paths[i];
    auto const &edges_i = edge_lists[i];
    for (std::size_t j = 0; j < i; ++j) {
      auto const &path_j = alt_paths[j];
      auto shared_len = 0.0;
      for (auto const &e : edges_i) {
        auto u = arlib::source(e, path_i);
        auto v = arlib::target(e, path_i);
        auto ok = arlib::edge(u, v, path_j).second;
        if (ok) {
          shared_len += weight[e];
        }
      }
      auto similarity = shared_len / path_j.length();
      if (similarity > theta) {
        return false;
      }
    }
  }
  return true;
}

constexpr std::string_view graph_gr = "d\n"
                                      "7 24\n"
                                      "0 1 6 0\n"
                                      "1 0 6 0\n"
                                      "0 3 3 0\n"
                                      "3 0 3 0\n"
                                      "0 2 4 0\n"
                                      "2 0 4 0\n"
                                      "1 6 6 0\n"
                                      "6 1 6 0\n"
                                      "3 4 5 0\n"
                                      "4 3 5 0\n"
                                      "3 1 2 0\n"
                                      "1 3 2 0\n"
                                      "3 2 3 0\n"
                                      "2 3 3 0\n"
                                      "2 4 5 0\n"
                                      "4 2 5 0\n"
                                      "3 5 3 0\n"
                                      "5 3 3 0\n"
                                      "4 5 1 0\n"
                                      "5 4 1 0\n"
                                      "4 6 3 0\n"
                                      "6 4 3 0\n"
                                      "5 6 2 0\n"
                                      "6 5 2 0\n";

constexpr std::string_view graph_gr_esx = "d\n"
                                          "7 24\n"
                                          "0 1 6 0\n"
                                          "1 0 6 0\n"
                                          "0 3 3 0\n"
                                          "3 0 3 0\n"
                                          "0 2 4 0\n"
                                          "2 0 4 0\n"
                                          "1 6 6 0\n"
                                          "6 1 6 0\n"
                                          "3 4 5 0\n"
                                          "4 3 5 0\n"
                                          "3 1 2 0\n"
                                          "1 3 2 0\n"
                                          "3 2 3 0\n"
                                          "2 3 3 0\n"
                                          "2 4 5 0\n"
                                          "4 2 5 0\n"
                                          "3 5 3 0\n"
                                          "5 3 3 0\n"
                                          "4 5 1 0\n"
                                          "5 4 1 0\n"
                                          "4 6 2 0\n"
                                          "6 4 2 0\n"
                                          "5 6 2 0\n"
                                          "6 5 2 0\n";

#endif

ext: hpp

max_stars_repo_name: ashishkashinath/arlib

max_issues_repo_name: ashishkashinath/arlib

max_forks_repo_name: ashishkashinath/arlib


text:
// Copyright 2012-2021 Jan Niklas Hasse <jhasse@bixense.com>
// For conditions of distribution and use, see copyright notice in LICENSE.txt

#include "../jngl.hpp"
#include "../jngl/init.hpp"

#include <algorithm>
#include <boost/math/constants/constants.hpp>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <optional>
#include <sstream>
#include <vector>

void drawMouse(jngl::Vec2);
void testKeys();
int performance = 1;
double factor = 0;

class Test : public jngl::Work {
public:
	Test() : fb2(jngl::getWindowSize()), logoWebp("jngl.webp") {
		jngl::setTitle(jngl::App::instance().getDisplayName() + " | UTF-8: äöüß");
		jngl::setIcon("jngl.png");
		jngl::setMouseVisible(false);
		frameTime = jngl::getTime();
		lastTime = jngl::getTime();
	}
	void step() override {
		rotate += 90.0 / 60.0; // 90 degree per second
		if (rotate > 360) {
			rotate = 0;
		}
		factor = std::sin(rotate / 360 * boost::math::constants::pi<double>());
		logoWebp.setPos(-logoWebp.getWidth() * factor, -logoWebp.getHeight() * factor);
		volume += static_cast<float>(jngl::getMouseWheel()) / 100.0f;
		if (jngl::keyPressed('p')) {
			jngl::stop("test.ogg");
			jngl::play("test.ogg");
		}
		if (jngl::keyPressed('s')) {
			useShader = !useShader;
			if (!shaderProgram) {
				fragmentShader = std::make_unique<jngl::Shader>(std::ifstream("data/blur.frag"),
				                                                jngl::Shader::Type::FRAGMENT);
				shaderProgram = std::make_unique<jngl::ShaderProgram>(jngl::Sprite::vertexShader(),
				                                                      *fragmentShader);
			}
		}
	}
	void drawBackground() const;
	void draw() const override {
		std::optional<jngl::FrameBuffer::Context> fb2Context;
		if (drawOnFrameBuffer) {
			fb2Context = fb2.use();
			fb2Context->clear(0xffffff_rgb);
		}
		jngl::pushMatrix();
		jngl::translate(-jngl::getScreenSize() / 2);
		jngl::pushMatrix();
		lastTime = jngl::getTime();
		for (int i = 0; i < 10; ++i) {
			if (jngl::keyDown(char('0' + i))) {
				performance = i == 0 ? 10 : i;
			}
		}
		drawBackground();
		jngl::setColor(0,0,0,255);
		jngl::pushMatrix();
		jngl::translate(650, 450);
		jngl::rotate(rotate);
		jngl::drawLine(-50, -50, 50, 50);
		jngl::popMatrix();
		jngl::setSpriteAlpha(200);
		jngl::translate(jngl::getScreenSize() / 2);
		jngl::rotate(rotate);
		jngl::setSpriteAlpha(static_cast<unsigned char>(std::abs(factor * 255)));
		if (useShader) {
			logoWebp.draw(jngl::modelview().scale(static_cast<float>(factor * 2)), &*shaderProgram);
		} else {
			logoWebp.draw(jngl::modelview().scale(static_cast<float>(factor * 2)));
		}
		jngl::setColor(0, 0, 0);
		jngl::drawRect(-125, 100, 250, 28);
		jngl::setFontColor(255, 255, 255);
		jngl::print("White text on black background", -115, 105);
		jngl::setFontColor(255, 255, 255);
		jngl::setFontSize(20);
		jngl::print("White text without background", -115, 135);
		jngl::setFontSize(12);
		jngl::popMatrix();
		std::stringstream sstream;
		sstream << "SPS" << (jngl::getVerticalSync() ? " (V-SYNC)" : "") << ": "
		        << jngl::getStepsPerSecond() << "\nFactor: " << factor
		        << "\nSize of double: " << sizeof(double);
		jngl::setColor(0, 0, 0);
		jngl::drawRect(0, 0, 200, 62);
		jngl::setFontColor(static_cast<unsigned char>(255 * (1 - factor)),
		                   static_cast<unsigned char>(255 * factor), 255);
		jngl::setFontByName("Courier New");
		jngl::print(sstream.str(), 5, 5);
		jngl::setFontByName("sans-serif");
		jngl::setFontColor(0,0,0);
		jngl::setFontByName("Times New Roman");
		jngl::print("Black text on white background", 5, 75);
		jngl::setFontByName("Arial");
		jngl::setFontSize(20);
		jngl::print("UTF-8:   ä ö ü ß Ĉ Ψ ≈", 5, 105);
		jngl::print(" $", static_cast<int>(jngl::getTextWidth("UTF-8:   ä ö ü ß Ĉ Ψ ≈") + 5), 105);
		jngl::setFontSize(12);
		jngl::print("Press 1-9 to test the performance\nPress E to show a error box.", 5, 135);
		if (jngl::keyPressed('e')) {
			jngl::errorMessage("Hello World!");
		}
		jngl::print("Press S to use the blur shader.", 5, 390);
		jngl::print("Press F to turn drawing on a FBO " + std::string(drawOnFrameBuffer ? "off" : "on") + ".", 5, 410);
		jngl::print("Press V to toggle V-SYNC.", 5, 430);
		if (jngl::keyPressed('v')) {
			jngl::setVerticalSync(!jngl::getVerticalSync());
		}
		sstream.str({});
		sstream << "Press A to turn Anti-Aliasing " << (jngl::getAntiAliasing() ? "off" : "on")
		        << ".";
		jngl::print(sstream.str(), 5, 450);
		if (jngl::keyPressed('a')) {
			jngl::setAntiAliasing(!jngl::getAntiAliasing());
		}
		jngl::print("Press F1 to switch fullscreen mode.", 5, 470);
		if (jngl::keyPressed(jngl::key::F1)) {
			jngl::setFullscreen(!jngl::getFullscreen());
		}
		jngl::print("Press K to test key codes.", 5, 490);
		jngl::print("Press P to play a sound.", 6, 510);
		static int playbackSpeed = 100;
		jngl::setPlaybackSpeed(float(playbackSpeed) / 100.0f);
		jngl::print("Press + and - to change the audio playback speed: " +
		      std::to_string(playbackSpeed) + " %", 6, 530);
		if (jngl::keyPressed('-')) {
			--playbackSpeed;
		}
		if (jngl::keyPressed('+')) {
			++playbackSpeed;
		}
		jngl::setVolume(volume);
		jngl::print("Use your mouse wheel to change the volume: " +
		                std::to_string(int(volume * 100)) + " %",
		            6, 550);
		jngl::setColor(0,0,255,128);
		if (drawOnFrameBuffer) {
			fb2Context = {};
			jngl::reset();
			jngl::setSpriteAlpha(255);
			fb2.draw(-jngl::getScreenSize() / 2);
		}
		if (jngl::keyPressed('f')) {
			drawOnFrameBuffer = !drawOnFrameBuffer;
		}
		jngl::popMatrix();
		drawMouse(jngl::getMousePos());
		if (++frameNumber == 500) {
			const auto seconds = jngl::getTime() - frameTime;
			std::cout << "It took " << seconds << " seconds to render 500 frames (~"
			          << int(500.0 / seconds) << " FPS)" << std::endl;
			frameNumber = 0;
			frameTime = jngl::getTime();
		}
		if (jngl::keyDown('k')) {
			testKeys();
		}
		if (jngl::keyPressed(jngl::key::Escape)) {
			jngl::quit();
		}
	}
private:
	mutable bool drawOnFrameBuffer = false;
	bool useShader = false;
	mutable double rotate = 0;
	mutable int frameNumber = 0;
	mutable double frameTime = 0;
	mutable double lastTime;
	mutable jngl::FrameBuffer fb2;
	jngl::Sprite logoWebp;
	float volume = 1;
	std::unique_ptr<jngl::Shader> vertexShader, fragmentShader;
	std::unique_ptr<jngl::ShaderProgram> shaderProgram;
};

std::function<std::shared_ptr<jngl::Work>()> jnglInit(jngl::AppParameters& params) {
	params.displayName = "JNGL Test Application";
	jngl::setPrefix(jngl::getBinaryPath());
	params.screenSize = { 800, 600 };
	return []() {
		std::cout << "Size of Desktop: " << jngl::getDesktopWidth() << "x"
		          << jngl::getDesktopHeight() << std::endl
		          << "Preferred language: " << jngl::getPreferredLanguage() << std::endl
		          << "Path of binary: " << jngl::getBinaryPath() << std::endl;
		jngl::onControllerChanged([]() {
			const auto controllers = jngl::getConnectedControllers();
			std::cout << "Number of connected controllers: " << controllers.size() << std::endl;
		});
		return std::make_shared<Test>();
	};
}

void Test::drawBackground() const {
	jngl::setSpriteAlpha(100);
	if (performance > 1) {
		const int size = performance * performance;
		for (int x = 0; x < size; ++x) {
			for (int y = 0; y < size; ++y) {
				logoWebp.draw(
				    jngl::modelview()
				        .translate(jngl::Vec2((x + .5) * jngl::getScreenWidth() / size,
				                              (y + .5) * jngl::getScreenHeight() / size))
				        .scale(float(jngl::getScreenWidth() / size / jngl::getWidth("jngl")),
				               float(jngl::getScreenHeight() / size / jngl::getHeight("jngl"))));
			}
		}
	} else {
		jngl::drawClipped("jngl", jngl::getScreenWidth() / 2 - jngl::getWidth("jngl") / 2.,
		                  jngl::getScreenHeight() / 2 - jngl::getHeight("jngl") / 2.,
		                  float(0.5 - factor / 2), float(0.5 + factor / 2),
		                  float(0.5 - factor / 2), float(0.5 + factor / 2));
	}
	jngl::setColor(255, 0, 0, 100);
	jngl::drawTriangle(600, 30, 700, 30, 650, 130);
	jngl::setColor(0, 255, 0, 100);
	jngl::drawRect(600, 400, 100, 100);
	jngl::setColor(0, 0, 255, 100);
	jngl::drawEllipse(80, 400, 50, 80);
}

void drawMouse(const jngl::Vec2 mouse) {
	jngl::translate(mouse.x, mouse.y);
	jngl::rotate(-45);
	jngl::setFontSize(30);
	jngl::setFontColor(10, 10, 200, 200);
	jngl::print("↑", -8, -2);
	jngl::setFontSize(12);
	jngl::reset();
}

class RecentlyPressedKey {
public:
	RecentlyPressedKey(std::string name, int x, int y)
	: name_(std::move(name)), alpha_(255), x_(x), y_(y), lastTime_(jngl::getTime()) {
	}
	void Draw() {
		double timeSinceLastFrame = jngl::getTime() - lastTime_;
		lastTime_ = jngl::getTime();
		alpha_ -= timeSinceLastFrame * 60;
		x_ += timeSinceLastFrame * 40;
		jngl::setFontColor(0, 0, 0, static_cast<unsigned char>(alpha_));
		jngl::print(name_, int(x_), int(y_));
		jngl::setFontColor(0, 0, 0, 255);
	}
	[[nodiscard]] int GetAlpha() const {
		return int(alpha_);
	}
private:
	std::string name_;
	double alpha_, x_, y_, lastTime_;
};

void testKeys() {
	jngl::setRelativeMouseMode(true);
	double xpos = 0;
	double ypos = 0;
	std::map<std::string, jngl::key::KeyType> keys;
	keys["Left"] = jngl::key::Left;
	keys["Up"] = jngl::key::Up;
	keys["Right"] = jngl::key::Right;
	keys["Down"] = jngl::key::Down;
	keys["PageUp"] = jngl::key::PageUp;
	keys["PageDown"] = jngl::key::PageDown;
	keys["Home"] = jngl::key::Home;
	keys["End"] = jngl::key::End;
	keys["BackSpace"] = jngl::key::BackSpace;
	keys["Tab"] = jngl::key::Tab;
	keys["Clear"] = jngl::key::Clear;
	keys["Return"] = jngl::key::Return;
	keys["Pause"] = jngl::key::Pause;
	keys["Escape"] = jngl::key::Escape;
	keys["Delete"] = jngl::key::Delete;
	keys["ControlL"] = jngl::key::ControlL;
	keys["ControlR"] = jngl::key::ControlR;
	keys["CapsLock"] = jngl::key::CapsLock;
	keys["AltL"] = jngl::key::AltL;
	keys["AltR"] = jngl::key::AltR;
	keys["SuperL"] = jngl::key::SuperL;
	keys["SuperR"] = jngl::key::SuperR;
	keys["Space"] = jngl::key::Space;
	keys["ShiftL"] = jngl::key::ShiftL;
	keys["ShiftR"] = jngl::key::ShiftR;
	keys["F1"] = jngl::key::F1;
	keys["F2"] = jngl::key::F2;
	keys["F3"] = jngl::key::F3;
	keys["F4"] = jngl::key::F4;
	keys["F5"] = jngl::key::F5;
	keys["F6"] = jngl::key::F6;
	keys["F7"] = jngl::key::F7;
	keys["F8"] = jngl::key::F8;
	keys["F9"] = jngl::key::F9;
	keys["F10"] = jngl::key::F10;
	keys["F11"] = jngl::key::F11;
	keys["F12"] = jngl::key::F12;
	keys["Any"] = jngl::key::Any;
	std::vector<RecentlyPressedKey> recentlyPressedKeys;
	std::string textInput;
	while (jngl::running()) {
		jngl::updateInput();
		jngl::setFontSize(10);
		jngl::pushMatrix();
		jngl::translate(-400, -300);
		int y = 10;
		for (const auto& it : keys) {
			if (jngl::keyDown(it.second)) {
				jngl::setFontColor(0, 0, 0);
			}
			else {
				jngl::setFontColor(150, 150, 150);
			}
			jngl::print(it.first, 100, y);
			if (jngl::keyPressed(it.second)){
				recentlyPressedKeys.emplace_back(it.first, 100, y);
			}
			y += 15;
		}
		y = 10;
		const auto printChar = [&recentlyPressedKeys](const char c, const int x, const int y) {
			char cString[2];
			cString[0] = c;
			cString[1] = 0;
			if(jngl::keyDown(c)) {
				jngl::setFontColor(0, 0, 0);
			}
			else {
				jngl::setFontColor(150, 150, 150);
			}
			jngl::print(cString, x, y);
			if (jngl::keyPressed(c)) {
				recentlyPressedKeys.emplace_back(cString, x, y);
			}
		};
		for (char c = '0'; c <= 'z'; ++c) {
			printChar(c, 380, y);
			if (c >= 'a' && c <= 'z') {
				printChar(char(toupper(c)), 610, y);
			}
			y += 15;
			if (c == '9') {
				c = 'a' - 1;
			}
		}

		if (textInput.size() > 40) { textInput.clear(); }
		textInput += jngl::getTextInput();
		jngl::setFontColor(0, 0, 0);
		jngl::print(textInput, 100, 583);

		std::map<std::string, jngl::mouse::Button> buttons;
		buttons["Left Mouse Button"] = jngl::mouse::Left;
		buttons["Middle Mouse Button"] = jngl::mouse::Middle;
		buttons["Right Mouse Button"] = jngl::mouse::Right;
		for (const auto& it : buttons) {
			if (jngl::mouseDown(it.second)) {
				jngl::setFontColor(0, 0, 0);
			}
			else {
				jngl::setFontColor(150, 150, 150);
			}
			jngl::print(it.first, 380, y);
			if (jngl::mousePressed(it.second)) {
				recentlyPressedKeys.emplace_back(it.first, 380, y);
			}
			y += 15;
		}
		auto end = recentlyPressedKeys.end();
		std::for_each(recentlyPressedKeys.begin(), end, [](RecentlyPressedKey& k) {
			k.Draw();
		});
		recentlyPressedKeys.erase(std::remove_if(recentlyPressedKeys.begin(), end,
		                          [](const RecentlyPressedKey& k) -> bool {
			return k.GetAlpha() <= 0;
		}), end);
		std::stringstream sstream;
		sstream << "X: " << jngl::getMousePos().x << "\nY: " << jngl::getMousePos().y << std::endl;
		jngl::print(sstream.str(), 5, 5);
		int controllerNr = 1;
		for (const auto& controller : jngl::getConnectedControllers()) {
			std::stringstream sstream;
			sstream << "Controller " << controllerNr << " connected." << std::endl
			        << "Trigger: " << controller->state(jngl::controller::LeftTrigger) << " " << controller->state(jngl::controller::RightTrigger)
			        << "\nA: " << controller->down(jngl::controller::A)
			        << " B: " << controller->down(jngl::controller::B)
			        << " X: " << controller->down(jngl::controller::X)
			        << " Y: " << controller->down(jngl::controller::Y)
			        << "\nLB: " << controller->down(jngl::controller::LeftButton)
			        << " RB: " << controller->down(jngl::controller::RightButton)
			        << " LT: " << controller->down(jngl::controller::LeftTrigger)
			        << " RT: " << controller->down(jngl::controller::RightTrigger)
			        << "\nLS: " << controller->down(jngl::controller::LeftStick)
			        << " RS: " << controller->down(jngl::controller::RightStick)
			        << " Start: " << controller->down(jngl::controller::Start)
			        << " Back: " << controller->down(jngl::controller::Back)
			        << "\n↑: " << controller->down(jngl::controller::DpadUp)
			        << " ↓: " << controller->down(jngl::controller::DpadDown)
			        << " ←: " << controller->down(jngl::controller::DpadLeft)
			        << " →: " << controller->down(jngl::controller::DpadRight);
			static uint8_t pressedFade = 150;
			if (controller->pressed(jngl::controller::A)) {
				assert(controller->pressed(jngl::controller::A));
				using namespace std::chrono_literals;
				controller->rumble(0.5f, 200ms);
				pressedFade = 0;
			} else {
				if (pressedFade < 150) {
					pressedFade += 10;
				}
			}
			jngl::setFontColor(pressedFade, pressedFade, pressedFade);

			jngl::pushMatrix();
			for (const jngl::Vec2& stick :
			     { jngl::Vec2(controller->state(jngl::controller::LeftStickX),
			                  -controller->state(jngl::controller::LeftStickY)),
			       jngl::Vec2(controller->state(jngl::controller::RightStickX),
			                  -controller->state(jngl::controller::RightStickY)) }) {
				const float circleRadius = 20;
				const auto circlePos = jngl::Vec2(530, double(-40 + controllerNr * 110));
				jngl::setColor(100, 100, 100, 255);
				jngl::drawEllipse(circlePos, circleRadius, circleRadius);
				jngl::setColor(255, 255, 255, 255);
				jngl::drawCircle(circlePos + circleRadius * stick, 4);
				jngl::translate(0, 2 * circleRadius + 10);
			}
			jngl::popMatrix();

			jngl::setColor(255, 255, 255, 150);
			jngl::drawRect({500, 40. + double(controllerNr - 1) * 110.}, {300, 120});
			jngl::print(sstream.str(), 558, 50 + (controllerNr - 1) * 110);
			++controllerNr;
		}
		jngl::popMatrix();
		if (jngl::getRelativeMouseMode()) {
			xpos += jngl::getMousePos().x;
			ypos += jngl::getMousePos().y;
			drawMouse({xpos, ypos});
		}
		if (jngl::keyPressed(jngl::key::Escape)) {
			jngl::setRelativeMouseMode(false);
			jngl::setMouseVisible(true);
			jngl::setMouse({xpos, ypos});
		}
		jngl::swapBuffers();
	}
}

max_stars_repo_name: jhasse/jngl

max_issues_repo_name: jhasse/jngl

max_forks_repo_name: jhasse/jngl


text: #include <boost/units/base_units/metric/liter.hpp>

max_stars_repo_name: miathedev/BoostForArduino

max_issues_repo_name: miathedev/BoostForArduino

max_forks_repo_name: miathedev/BoostForArduino


text:
#ifndef BOOST_THREAD_QUEUE_VIEWS_HPP
#define BOOST_THREAD_QUEUE_VIEWS_HPP

//////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Vicente J. Botet Escriba 2014. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/thread for documentation.
//
//////////////////////////////////////////////////////////////////////////////

#include <boost/thread/detail/config.hpp>
#include <boost/thread/detail/move.hpp>
#include <boost/thread/concurrent_queues/queue_op_status.hpp>
#include <boost/thread/concurrent_queues/deque_base.hpp>

#include <boost/config/abi_prefix.hpp>

namespace boost
{
namespace concurrent
{

  template <typename Queue>
  class deque_back_view
  {
   Queue* queue;
  public:
    typedef typename Queue::value_type value_type;
    typedef typename Queue::size_type size_type;

    // Constructors/Assignment/Destructors
    deque_back_view(Queue& q) BOOST_NOEXCEPT : queue(&q) {}

    // Observers
    bool empty() const  { return queue->empty(); }
    bool full() const { return queue->full(); }
    size_type size() const { return queue->size(); }
    bool closed() const { return queue->closed(); }

    // Modifiers
    void close() { queue->close(); }

    void push(const value_type& x) { queue->push_back(x); }

    void pull(value_type& x) { queue->pull_back(x); }
    // enable_if is_nothrow_copy_movable<value_type>
    value_type pull()  { return queue->pull_back(); }

    queue_op_status try_push(const value_type& x) { return queue->try_push_back(x); }

    queue_op_status try_pull(value_type& x) { return queue->try_pull_back(x); }

    queue_op_status nonblocking_push(const value_type& x) { return queue->nonblocking_push_back(x); }

    queue_op_status nonblocking_pull(value_type& x) { return queue->nonblocking_pull_back(x); }

    queue_op_status wait_push(const value_type& x) { return queue->wait_push_back(x); }
    queue_op_status wait_pull(value_type& x) { return queue->wait_pull_back(x); }

    void push(BOOST_THREAD_RV_REF(value_type) x) { queue->push_back(boost::move(x)); }
    queue_op_status try_push(BOOST_THREAD_RV_REF(value_type) x) { return queue->try_push_back(boost::move(x)); }
    queue_op_status nonblocking_push(BOOST_THREAD_RV_REF(value_type) x) { return queue->nonblocking_push_back(boost::move(x)); }
    queue_op_status wait_push(BOOST_THREAD_RV_REF(value_type) x) { return queue->wait_push_back(boost::move(x)); }
  };

  template <typename Queue>
  class deque_front_view
  {
   Queue* queue;
  public:
    typedef typename Queue::value_type value_type;
    typedef typename Queue::size_type size_type;

    // Constructors/Assignment/Destructors
    deque_front_view(Queue& q) BOOST_NOEXCEPT : queue(&q) {}

    // Observers
    bool empty() const  { return queue->empty(); }
    bool full() const { return queue->full(); }
    size_type size() const { return queue->size(); }
    bool closed() const { return queue->closed(); }

    // Modifiers
    void close() { queue->close(); }

    void push(const value_type& x) { queue->push_front(x); }

    void pull(value_type& x) { queue->pull_front(x); };
    // enable_if is_nothrow_copy_movable<value_type>
    value_type pull()  { return queue->pull_front(); }

    queue_op_status try_push(const value_type& x) { return queue->try_push_front(x); }

    queue_op_status try_pull(value_type& x) { return queue->try_pull_front(x); }

    queue_op_status nonblocking_push(const value_type& x) { return queue->nonblocking_push_front(x); }

    queue_op_status nonblocking_pull(value_type& x) { return queue->nonblocking_pull_front(x); }

    queue_op_status wait_push(const value_type& x) { return queue->wait_push_front(x); }
    queue_op_status wait_pull(value_type& x) { return queue->wait_pull_front(x); }
    void push(BOOST_THREAD_RV_REF(value_type) x) { queue->push_front(forward<value_type>(x)); }
    queue_op_status try_push(BOOST_THREAD_RV_REF(value_type) x) { return queue->try_push_front(forward<value_type>(x)); }
    queue_op_status nonblocking_push(BOOST_THREAD_RV_REF(value_type) x) { return queue->nonblocking_push_front(forward<value_type>(x)); }
    queue_op_status wait_push(BOOST_THREAD_RV_REF(value_type) x) { return queue->wait_push_front(forward<value_type>(x)); }

  };

#if ! defined BOOST_NO_CXX11_TEMPLATE_ALIASES

  template <class T>
  using deque_back = deque_back_view<deque_base<T> > ;
  template <class T>
  using deque_front = deque_front_view<deque_base<T> > ;

#else

  template <class T>
  struct deque_back : deque_back_view<deque_base<T> >
  {
    typedef deque_back_view<deque_base<T> > base_type;
    deque_back(deque_base<T>& q) BOOST_NOEXCEPT : base_type(q) {}
  };
  template <class T>
  struct deque_front : deque_front_view<deque_base<T> >
  {
    typedef deque_front_view<deque_base<T> > base_type;
    deque_front(deque_base<T>& q) BOOST_NOEXCEPT : base_type(q) {}

  };

#endif

//  template <class Queue>
//  deque_back_view<Queue> back(Queue & q) { return deque_back_view<Queue>(q); }
//  template <class Queue>
//  deque_front_view<Queue> front(Queue & q) { return deque_front_view<Queue>(q); }
//#if 0
//  template <class T>
//  deque_back<T> back(deque_base<T> & q) { return deque_back<T>(q); }
//  template <class T>
//  deque_front<T> front(deque_base<T> & q) { return deque_front<T>(q); }
//#else
//  template <class T>
//  typename deque_back<T>::type back(deque_base<T> & q) { return typename deque_back<T>::type(q); }
//  template <class T>
//  typename deque_front<T>::type front(deque_base<T> & q) { return typename deque_front<T>::type(q); }
//#endif
}

using concurrent::deque_back_view;
using concurrent::deque_front_view;
using concurrent::deque_back;
using concurrent::deque_front;
//using concurrent::back;
//using concurrent::front;

}

#include <boost/config/abi_suffix.hpp>

#endif


text:
#include <boost/thread.hpp>
#include <boost/chrono.hpp>
#include <iostream>

void wait(int seconds)
{
  boost::this_thread::sleep_for(boost::chrono::seconds{seconds});
}

void thread(int number)
{
  for (int i = 0; i < 5; ++i)
  {
    wait(1);
    std::cout << number <<":"<< i << "\n";
  }
}

void thread2(int number)
{
  for (int i = 0; i < 5; ++i)
  {
    wait(1);
    std::cout << number <<":"<< i << "\n";
  }
}

int main()
{
  boost::thread t{thread,1};
  boost::thread t2{thread,2};
  boost::thread t3(thread,3);

  t.join();
  t2.join();
  t3.join();
}