Skip to content

Instantly share code, notes, and snippets.

View andreysolovyev381's full-sized avatar

Andrey Solovyev andreysolovyev381

View GitHub Profile
@andreysolovyev381
andreysolovyev381 / gist:66299b58e768528d3c5964f925a45e0c
Last active May 26, 2025 07:28
std:: vs std::pmr:: addresses
#include <iostream>
#include <memory_resource>
#include <unordered_map>
#include <string>
#include <vector>
void print_string_info(const std::string& str, const std::string& name, const void* buffer_start, const void* buffer_end) {
std::cout << name << " address: " << reinterpret_cast<uintptr_t>(str.data()) << std::endl;
bool in_buffer = (void*)str.data() >= buffer_start && (void*)str.data() < buffer_end;
std::cout << name << " in buffer: " << (in_buffer ? "Yes" : "No") << std::endl;
@andreysolovyev381
andreysolovyev381 / Simple Unit test.cpp
Created October 4, 2019 08:37
Utils for running a simple Unit Test for any func. Usually "void TestSomething()"
/*
* usage:
* TestRunner tr;
* RUN_TEST(tr, FUNC_NAME);
*
*/
template<class T, class U>
void AssertEqual(const T& t, const U& u, const string& hint = {}) {
@andreysolovyev381
andreysolovyev381 / Log_Duration macros.cpp
Created October 4, 2019 08:18
c++ provides out-of-the box profiler for a piece of code in {}
#include <chrono>
#include <iostream>
#include <string>
using namespace std::chrono;
class LogDuration {
public:
explicit LogDuration(const string& msg = "")
: message(msg + ": ")
@andreysolovyev381
andreysolovyev381 / IteratorRange template.cpp
Created October 4, 2019 08:04
c++ IteratorRange Template (Random Access)
//Iterator range
template <typename Iterator>
struct IteratorRange {
IteratorRange(Iterator First, Iterator Last) : first(First), last(Last) {}
Iterator first , last;
Iterator begin () const {
return first;
}
Iterator end () const {
return last;}