Skip to content

Instantly share code, notes, and snippets.

@barahilia
Last active November 8, 2019 08:37
Show Gist options
  • Save barahilia/916161bf6355b6819b7da6b6f44c9a1d to your computer and use it in GitHub Desktop.
Save barahilia/916161bf6355b6819b7da6b6f44c9a1d to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
class A {
public:
int a;
A() : a(3) { cout << "A()" << endl; }
A(const A& other) : a(other.a) { cout << "A(const A&)" << endl; }
A& operator=(const A& other) { a = other.a; cout << "A.operator=(const A&)" << endl; }
~A() { cout << "~A()" << endl; }
};
int main() {
cout << "hi" << endl;
A a;
A b(a);
A c = A();
c = b;
return 0;
}
#include <iostream>
#include <exception>
using namespace std;
class A {
public:
int _a;
A(int a) throw(exception)
: _a(a)
{ _a = a; }
A(string s) throw(exception);
void b() throw(exception) { _a++; }
};
A::A(string s) throw(exception) : _a(0)
{ _a = 0; }
int main() {
A aa(5); A bb("");
cout << "Success" << endl;
}
#include <iostream>
#include <sstream>
using namespace std;
int main() {
cout << "Hi" << endl;
stringstream ss;
ss << "mama mila ramu";
string s;
ss >> s;
int i = 42;
ss.exceptions ( stringstream::failbit );
try {
ss >> i;
} catch (exception) {
cout << "catched" << endl;
}
if ( ss.fail() ) cout << "failure 1" << endl;
ss.clear();
ss >> s;
if ( ss.fail() ) cout << "failure 2" << endl;
cout << s << ' ' << i << endl;
return 0;
}
template <int N> class D {
public: typedef char b[N];
};
int main() {
D<0> a;
D<-1> b;
return 0;
}
#include <iostream>
class C { };
int main() {
std::cout << "C size = " << sizeof(C) << std::endl;
}
#include <iterator>
#include <iostream>
#include <fstream>
#include <list>
using namespace std;
int main() {
ifstream f("ints.txt");
int test ();
list<int> data((istream_iterator<int>(f)),
istream_iterator<int>() );
cout << data.size() << endl;
copy( data.begin(),
--(data.end()),
ostream_iterator<int> (cout, " <-> ") );
cout << *data.rbegin() << endl;
return 0;
}
#include <iostream>
using namespace std;
typedef void (*foo) (int);
void a(int i) { cout << "a(" << i << ')' << endl; }
int main() {
cout << "Hi" << endl;
a(42);
foo b( a );
b(7);
foo c();
c();
return 0;
}
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<double> v;
cout << v.max_size() << endl;
return 0;
}
#include <iostream>
#include <boost/smart_ptr.hpp>
using namespace std;
struct BaseUse {
};
struct BaseStream {
BaseStream() {cout<<"BaseStream()"<<endl;}
template<class T>
BaseStream& operator<< (const T& t) {
cout << '_' << t;
}
};
struct Db {
template<class T>
BaseStream operator<< (const T& t) {
BaseStream bs;
bs << t;
return bs;
}
};
int main() {
cout << "Hi" << endl;
Db db;
db << "Ura " << 5 << "\n";
return 0;
}
#include <iostream>
using namespace std;
int f(double x) { return int(x*x*x + x*x - x*6); }
int main() {
cout << "Hi" << endl;
for (int y = 10; y>=-10; y--) {
for (double x = -3.5; x<=3.5; x+=0.1) {
if ( f(x) == y ) {
cout << '*';
} else {
cout << ' ';
}
}
cout << endl;
}
return 0;
}
template<typename T>
void f1 (T x )
{
g1(x);
}
void g1(int)
{
}
int main()
{
f1(7);
}
#include <iostream>
template<typename T>
T const& max (T const&, T const&);
int main()
{
std::cout << max(7, 43) << std::endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment