Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template <typename T>
- struct deleter {
- void operator()(T* ptr) {
- delete ptr;
- }
- };
- struct S {
- int* p = new int(3);
- int x;
- S(int el) : x(el) {}
- ~S() {
- delete p;
- }
- };
- int main() {
- // void* p = ::operator new(sizeof(std::string));
- // new(p) std::string(3, 'a');
- // new(p) std::string(5, 'b');
- // ::operator delete(p);
- // std::string* p = new std::string(4, 'a');
- // std::cout << *p << " ";
- // new(p) std::string(3, 'b');
- // std::cout << *p;
- // delete p;
- S* p = new S(4);
- // deleter<S> del;
- // del.operator()(p);
- std::cout << p->x << " ";
- new(p) S(5);
- std::cout << p->x;
- delete p;
- }
- #include <iostream>
- template <class Arg>
- Arg sum(Arg arg) { return arg; }
- template <class First, class... Other>
- auto sum(First first, Other... other)
- {
- return first + sum(other...);
- }
- int main() {
- std::cout << sum(1, 3, 4, 5);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement