Skip to content

Instantly share code, notes, and snippets.

@RedBeard0531
Created November 18, 2014 21:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RedBeard0531/f929d9da37c805ba2563 to your computer and use it in GitHub Desktop.
Save RedBeard0531/f929d9da37c805ba2563 to your computer and use it in GitHub Desktop.
Item6
#include <boost/static_assert.hpp>
#include <type_traits>
#include <vector>
int main() {
////////////////// PROXY OBJECTS /////////////////
{
auto bools = std::vector<bool>{true, false};
auto b0 = bools[0];
//BOOST_STATIC_ASSERT(std::is_same<decltype(b0), bool>());
auto b1 = bool(bools[1]); // or static_cast<bool>(bools[1])
BOOST_STATIC_ASSERT(std::is_same<decltype(b1), bool>());
}
///////////////// NUMERIC CONVERSIONS /////////////
{
auto doubleFunc = []{ return 1.0; };
auto anInt = int(doubleFunc()); // or static_cast<int>(doubleFuct());
}
///////////////// DEFAULT CONSTRUCTION /////////////
{
struct Thing {};
struct Thing2 { int i; };
// Thing aThing();
auto aThing = Thing();
auto aThing2 = Thing2();
auto aVector = std::vector<int>();
auto an = int();
}
///////////////// CONSTRUCTORS WITH ARGS /////////////
{
struct Thing {
Thing(int i, double d);
int i;
double d;
};
// Thing aThing(1, 3.0);
auto aThing = Thing(1, 3.0);
auto anotherThing = Thing{1, 3.0};
auto aVector = std::vector<Thing>(3, Thing(1, 3.0));
auto anotherVector = std::vector<Thing>(3, Thing{1, 3.0});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment