Category : std

As mentioned in the title I want to generate a random floating-point number between -10 and 10 but I want to make it so that it can’t generate a number between -1.99 and 1.99. My code for randomly generating numbers: std::random_device random; std::mt19937 gen(random()); std::uniform_real_distribution<float> dis(-10.0f, 10.0f); for (int n = 0; n < 10; ..

Read more

I have a function with signature: template<class Type> bool isPrime(const Type& n,float (*fSqrt)(float),bool debug = false) which works fine. But, template<class Type> bool isPrime(const Type& n,std::function<float(float)> fSqrt,bool debug = false) causes compile-error. How to replace float (*fSqrt)(float) with std::function<float(float) fSqrt> ? Please note: My ultimate objective is std::function<float(Type)>, where Type is templated. Wandbox (https://wandbox.org/) shows: ..

Read more

I wrote a struct to maintain a state of tic-tac-toe game. struct Board{ std::vector<std::vector<int>> board; Board() { board = std::vector<std::vector<int>> (3, std::vector<int> (3)); } std::vector<int> & operator[](int id) { return board[id]; } int & operator[](std::pair<int, int> pos) { return board[pos.first][pos.second]; } }; It works fine, and I can access the values within the struct in ..

Read more

I am writing a program to transfer re -> nfa -> dfa. Complete code see: https://paste.ubuntu.com/p/7DYncY8R9G/ it’s work well in msvc. when nfa -> dfa, I use this data structure。 using node_set = std::unordered_set<int>; struct set_hash { std::size_t operator()(const node_set& s) const noexcept { std::size_t res; for (auto i : s) res ^= ((i >> ..

Read more