Skip to content

Instantly share code, notes, and snippets.

View asit-dhal's full-sized avatar

Asit Kumar Dhal asit-dhal

View GitHub Profile
struct A1 {
A1(int w, int x, int y) : w(w), x(x), y(y){}
int w;
int x;
int y;
};
struct B1 : public A1 {
B1(int w, int x, int y) : A1(w, x, y) {}
};
struct A {
A(int w, int x, int y) : w(w), x(x), y(y){}
int w;
int x;
int y;
};
struct B : public A {
B(int w, int x, int y, int z):A(w, x, y),z(z) {}
int z;
struct A {
A(int w, int x, int y, int z) : w(w), x(x), y(y), z(z){}
int w;
int x;
int y;
private:
int z;
};
int main()
int main ()
{
std::map<std::string, std::string> countryCapitals {
{"India", "New Delhi"},
{"Germany", "Berlin"},
{"USA", "Newyork"}
};
if (auto const [itr, success] = countryCapitals.insert({"USA", "Moscow"}); success) {
std::cout << "insert successful for country: " << itr->first << " capital: " << itr->second << std::endl;
int main ()
{
std::map<std::string, std::string> countryCapitals {
{"India", "New Delhi"},
{"Germany", "Berlin"},
{"USA", "Newyork"}
};
for (auto const& [country, capital] : countryCapitals) {
std::cout << country << " => " << capital << std::endl;
int main ()
{
std::array<int, 3> cppArr{1, 2,3};
auto [e1, e2, e3] = cppArr;
assert(e1 == 1);
assert(e2 == 2);
assert(e3 == 3);
int cArr[] = {10, 20, 30};
struct RetVal
{
int a;
std::string b;
};
RetVal doSomething()
{
// do something
return {10, "Test"};
int main ()
{
auto t = std::make_tuple (10, 'a', "Value");
auto& [t1, t2, t3] = t;
(void)t3;
t1 = 20;
t2 = 'z';
assert (t1 == std::get<0>(t));
assert (t2 == std::get<1>(t));
int main ()
{
auto t = std::make_tuple (10, 'a', "Value");
int t1;
std::string t3;
std::tie(t1, std::ignore, t3) = t;
assert (t1 == 10);
assert (t3 == "Value");
int main()
{
auto t = std::make_tuple(10, 'a', "Value");
auto [t1, t2, t3] = t;
assert(t1 == 10);
assert(t2 == 'a');
assert(t3 == "Value");
return 0;