Skip to content

Instantly share code, notes, and snippets.

View BillyONeal's full-sized avatar

Billy O'Neal BillyONeal

View GitHub Profile
@BillyONeal
BillyONeal / example_use.cpp
Last active November 19, 2022 14:20
Death testing
#include <stddef.h>
#include <string_view>
#include <pmretvals.h>
#include <test_death.hpp>
using namespace std;
int test_case_operator_dereference_value_initalized_iterator() {
string_view::iterator it; // note: for IDL to work correctly, default init and value init are equivalent
; Function compile flags: /Ogtpy
; COMDAT ?swap@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEXAAV12@@Z
_TEXT SEGMENT
__Right$ = 8 ; size = 4
?swap@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEXAAV12@@Z PROC ; std::basic_string<char,std::char_traits<char>,std::allocator<char> >::swap, COMDAT
; _this$ = ecx
; File c:\program files (x86)\microsoft visual studio 14.0\vc\include\xstring
; Line 1857
00000 56 push esi
00001 57 push edi
@BillyONeal
BillyONeal / equivalent.cpp
Created February 21, 2017 05:39
std::filesystem::equivalent
#include <vcruntime.h>
__std_win32_error __std_fs_equivalent(bool * _Result, const wchar_t *_Path1, const wchar_t *_Path2) noexcept
{ // test for equivalent file names
const __vcp_unique_handle _Handle1(_FilesysOpenFile(_Path1, FILE_READ_ATTRIBUTES,
FILE_FLAG_BACKUP_SEMANTICS));
if (!_Handle1.is_valid())
{
*_Result = false;
return (GetLastError());
@BillyONeal
BillyONeal / boyer_moore.cpp
Created April 1, 2017 01:34
Boyer-Moore Searcher Comparative Benchmark
#include <algorithm>
#include <functional>
#include <string>
#include <string_view>
#include <benchmark/benchmark.h>
#include "file.hpp"
#define NOMINMAX
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
@BillyONeal
BillyONeal / algorithm.cpp
Created April 3, 2017 22:21
MSVC++ std::clamp
#if _HAS_CXX17
// FUNCTION TEMPLATE clamp
template<class _Ty,
class _Pr>
constexpr const _Ty& clamp(const _Ty& _Val, const _Ty& _Min_val,
const _Ty& _Max_val, _Pr _Pred)
{ // returns _Val constrained to [_Min_val, _Max_val] ordered by _Pred
#if _ITERATOR_DEBUG_LEVEL == 2
return (_DEBUG_LT_PRED(_Pred, _Max_val, _Min_val)
? (_DEBUG_ERROR("invalid bounds arguments passed to std::clamp"), _Val)
template <class T>
class StdAllocatorSysMem
{
public:
typedef T value_type;
StdAllocatorSysMem() = default;
StdAllocatorSysMem(const StdAllocatorSysMem&) = default;
template <class Other>
StdAllocatorSysMem(const StdAllocatorSysMem<Other>&)
@BillyONeal
BillyONeal / algorithm.cpp
Last active May 30, 2017 23:57
inplace_merge overhaul
template<class _BidIt,
class _Diff,
class _Ty> inline
_BidIt _Buffered_rotate_unchecked(const _BidIt _First, const _BidIt _Mid, const _BidIt _Last,
const _Diff _Count1, const _Diff _Count2, _Temporary_buffer<_Ty>& _Temp_buf)
{ // rotate [_First, _Last) using temp buffer
// precondition: _Count1 == distance(_First, _Mid)
// precondition: _Count2 == distance(_Mid, _Last)
if (_Count1 == 0)
{ // do nothing
@BillyONeal
BillyONeal / mutex.hpp
Created May 31, 2017 23:56
Mutex Next
// CLASS mutex
class mutex
{ // class for mutual exclusion
public:
constexpr mutex() _NOEXCEPT
: _Data()
{ // construct std::mutex
}
mutex(const mutex&) = delete;
@BillyONeal
BillyONeal / nextbench.cpp
Created June 3, 2017 02:25
std::next benchmark
#include <stdio.h>
#include <algorithm>
#include <chrono>
#include <functional>
#include <iterator>
#include <random>
#include <vector>
using namespace std;
using namespace std::chrono;
@BillyONeal
BillyONeal / sorttest.cpp
Created June 8, 2017 07:59
Sort Determinisim
#include <assert.h>
#include <stdio.h>
#include <algorithm>
#include <random>
#include <vector>
using namespace std;
struct kv {
unsigned int significant;