#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <algorithm>
#include <vector>
#include <iostream>
static int _argc;
static char **_argv;
using std::vector;
using std::begin;
using std::end;
struct Transform {
const vector<int> &items;
explicit Transform(vector<int> const &items) : items{items} {}
const Transform &operator>>(std::string const &val) const {
std::cout << val << ": ";
return *this;
}
const Transform &operator>>(vector<int>(FUNC)(vector<int>)) const{
auto const ret = FUNC(items);
std::cout << "(";
std::for_each(begin(ret), end(ret), [](auto const &v) {
std::cout << v << ",";
});
std::cout << "\b)" << std::endl;
return *this;
// It segfaults here on function exit
}
};
int main() {
vector<int> items {1, 2, 3, 4, 4, 5, 6, 7};
auto _ = Transform(items);
_ >> "example" >> [](vector<int> src) -> vector<int> {
return src;
};
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2luY2x1ZGUgPHVuaXN0ZC5oPgojaW5jbHVkZSA8c2lnbmFsLmg+CiNpbmNsdWRlIDxhbGdvcml0aG0+CiNpbmNsdWRlIDx2ZWN0b3I+CiNpbmNsdWRlIDxpb3N0cmVhbT4KCgpzdGF0aWMgaW50IF9hcmdjOwpzdGF0aWMgY2hhciAqKl9hcmd2Owp1c2luZyBzdGQ6OnZlY3RvcjsKdXNpbmcgc3RkOjpiZWdpbjsKdXNpbmcgc3RkOjplbmQ7CgpzdHJ1Y3QgVHJhbnNmb3JtIHsKICAgIGNvbnN0IHZlY3RvcjxpbnQ+ICZpdGVtczsKCiAgICBleHBsaWNpdCBUcmFuc2Zvcm0odmVjdG9yPGludD4gY29uc3QgJml0ZW1zKSA6IGl0ZW1ze2l0ZW1zfSB7fQoKICAgIGNvbnN0IFRyYW5zZm9ybSAmb3BlcmF0b3I+PihzdGQ6OnN0cmluZyBjb25zdCAmdmFsKSBjb25zdCB7CiAgICAgICAgc3RkOjpjb3V0IDw8IHZhbCA8PCAiOiAiOwogICAgICAgIHJldHVybiAqdGhpczsKICAgIH0KCiAg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