This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// requires C++23 or later | |
#include <bit> | |
#include <concepts> | |
template <std::integral T> | |
constexpr T hton(T value) noexcept | |
{ | |
if constexpr (std::endian::native == std::endian::little) { | |
return std::byteswap(value); | |
} else { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <memory> | |
#include <vector> | |
#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_DEBUG | |
#include "spdlog/spdlog.h" | |
#include "spdlog/sinks/stdout_color_sinks.h" | |
#include "spdlog/sinks/daily_file_sink.h" | |
#include "spdlog/sinks/rotating_file_sink.h" | |
int main(int argc, char* argv[]) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <condition_variable> | |
#include <mutex> | |
#include <thread> | |
class fair_mutex { | |
std::mutex mtx_; | |
std::condition_variable cv_; | |
unsigned int next_, curr_; | |
public: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <initializer_list> | |
namespace mock { | |
template <class T> | |
struct allocator {}; | |
template <class T> | |
struct char_traits {}; | |
// C++20 https://timsong-cpp.github.io/cppwp/n4861/basic.string | |
template<class charT, class traits = char_traits<charT>, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <algorithm> | |
#include <iostream> | |
#include <string> | |
#include <string_view> | |
#include <ranges> | |
int main() { | |
std::string_view str = "apple,banana,cinnamon"; | |
for (auto rev_item: str | std::views::reverse | std::views::split(',')) { | |
static_assert( std::ranges::forward_range<decltype(rev_item)>); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
prog.cc: In function 'int main()': | |
prog.cc:6:19: error: no match for 'operator|' (operand types are 'std::forward_list<int, std::allocator<int> >' and 'const std::ranges::views::_Reverse') | |
6 | for (int _: lst | std::views::reverse) {} | |
| ~~~ ^ ~~~~~~~~~~~~~~~~~~~ | |
| | | | |
| | const std::ranges::views::_Reverse | |
| std::forward_list<int, std::allocator<int> > | |
In file included from prog.cc:2: | |
/opt/wandbox/gcc-head/include/c++/12.0.0/ranges:818:7: note: candidate: 'template<class _Lhs, class _Rhs> requires (derived_from<_Lhs, std::ranges::views::__adaptor::_RangeAdaptorClosure>) && (derived_from<_Rhs, std::ranges::views::__adaptor::_RangeAdaptorClosure>) constexpr auto std::ranges::views::__adaptor::operator|(_Lhs, _Rhs)' | |
818 | operator|(_Lhs __lhs, _Rhs __rhs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void KillProcessTree(System.Diagnostics.Process process) | |
{ | |
string taskkill = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "taskkill.exe"); | |
using (var procKiller = new System.Diagnostics.Process()) { | |
procKiller.StartInfo.FileName = taskkill; | |
procKiller.StartInfo.Arguments = string.Format("/PID {0} /T /F", process.Id); | |
procKiller.StartInfo.CreateNoWindow = true; | |
procKiller.StartInfo.UseShellExecute = false; | |
procKiller.Start(); | |
procKiller.WaitForExit(1000); // wait 1sec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bool starts_with_utf8bom(std::string_view s) | |
{ | |
constexpr char utf8_bom[3] = { 0xEF, 0xBB, 0xBF }; | |
return s.length() >= 3 && std::equal(utf8_bom, utf8_bom + 3, s.begin()); | |
} | |
std::string& erase_utf8bom(std::string& text) | |
{ | |
if (starts_with_utf8bom(text)) { | |
text.erase(0, 3); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <type_traits> | |
int main() { | |
int x = 42; | |
static_assert(std::is_same_v<decltype( x ), int>); | |
static_assert(std::is_same_v<decltype((x)), int&>); | |
int (y) = 42; // redundant parentheses | |
static_assert(std::is_same_v<decltype( y ), int>); | |
static_assert(std::is_same_v<decltype((y)), int&>); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
""" | |
C++ source text converter for PO3OOrO. | |
Copyright (C) 2016 yohhoy. | |
PO3OORO: Enhancing the C++ Basic Character Set with Standard Character Mappings | |
https://isocpp.org/files/papers/PO3OOrO.pdf | |
Special thanks to http://emojipedia.org/ |