Skip to content

Instantly share code, notes, and snippets.

@TheEyesightDim
TheEyesightDim / header.h
Last active July 1, 2018 08:26
Demonstrates the use of a variadic template function within a class template.
#ifndef HEADER_H
#define HEADER_H
#include <utility>
#include <algorithm>
#include <array>
template <typename T>
class MyClass
{
@TheEyesightDim
TheEyesightDim / tuples.cpp
Last active July 1, 2018 08:23
Example of working with tuples to return multiple values; Example of using tuples in place of structs
#include <tuple>
#include <iostream>
using std::tuple;
using std::tie;
using std::make_tuple;
using std::cout;
class rectangle
{
@TheEyesightDim
TheEyesightDim / inputcheck.cpp
Last active March 1, 2017 08:05
Detect invalid input and clear input stream, C++ STL
do{
cout<<"Input \"1\" or \"0\": ";
cin >> scenario;
if(cin.fail() || scenario < 0 || scenario > 1){
cin.clear(); //clear failure state
cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); //ignore and discard failed input up to and including newline
cout << "\nInput failed. Trying again..." << endl;
continue;
}