Skip to content

Instantly share code, notes, and snippets.

@plasticbox
plasticbox / getcmdoption.cpp
Last active August 7, 2022 19:57
Simple Parse Command Line Arguments in C++
std::string getCmdOption(int argc, char* argv[], const std::string& option)
{
std::string cmd;
for( int i = 0; i < argc; ++i)
{
std::string arg = argv[i];
if(0 == arg.find(option))
{
std::size_t found = arg.find_first_of(option);
cmd =arg.substr(found + 1);
@plasticbox
plasticbox / fixedvector.h
Created June 16, 2016 06:08
FixedVector C++
template<typename T, unsigned int maxSize>
class FixedVector : public std::vector<T>
{
public:
FixedVector() { _maxSize = maxSize; }
bool push_back(const T& elem)
{
if(_maxSize > size())
{
std::vector<T>::push_back(elem);
@plasticbox
plasticbox / std::packaged_task.cpp
Last active November 10, 2016 14:46
std::packaged_task
#include <iostream>
#include <thread>
#include <future>
#include <queue>
class ITask
{
public:
virtual ~ITask() {};
virtual void execute() = 0;