Skip to content

Instantly share code, notes, and snippets.

@cdacamar
cdacamar / frequencies.cpp
Created January 8, 2020 05:20
Word frequencies
// cl /EHsc /std:c++latest /permissive- /O2 word_frequencies.cpp
#include <cctype>
#include <cstdio>
#include <algorithm>
#include <charconv>
#include <fstream>
#include <string>
#include <string_view>
#include <unordered_map>
void do_thing();
std::thread t1{[] { std::cout<<"Hello, World!\n"; }};
std::thread t2{do_thing};
t1.join();
t2.join();
// most common use case for std::thread, the function invoke ctor
template<typename Function, typename... Args>
explicit thread(Function&& f, Args&&... args);
DWORD WINAPI DoThing( LPVOID );
DWORD ThreadID; // why?
auto threadHandle = CreateThread(
NULL, // default security attributes
0, // default stack size
(LPTHREAD_START_ROUTINE) DoThing,
NULL, // no thread function arguments
0, // default creation flags
&ThreadID); // receive thread identifier
HANDLE WINAPI CreateThread(
_In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes,
_In_ SIZE_T dwStackSize,
_In_ LPTHREAD_START_ROUTINE lpStartAddress,
_In_opt_ LPVOID lpParameter,
_In_ DWORD dwCreationFlags,
_Out_opt_ LPDWORD lpThreadId
);
struct circle_t;
struct triangle_t;
struct square_t;
struct shape_t {
using visitor_t = vdsp::visitor_t<circle_t, triangle_t, square_t>;
virtual void accept(const visitor_t&) const = 0;
virtual void do_thing() const = 0;
};
@cdacamar
cdacamar / beefy_std_find.cpp
Created June 23, 2016 02:54
std::find, but beefy
#include <array> // std::array
#include <iostream> // std::cout
#include <iterator> // std::begin, std::end, std::distance
#include <tuple> // std::tuple
#include <type_traits> // std::decay_t
#include <utility> // std::integer_sequence, std::forward
#include <vector> // std::vector
namespace detail
{