Commit e6ce4ddd authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 40deb7ed
......@@ -34,19 +34,6 @@ using namespace golang;
#include <memory>
#if 0
// error
error error::New(const string &text) {
error err;
err._err = text;
return err;
}
string error::Error() const {
return _err;
}
#endif
// io::
namespace io {
......@@ -250,32 +237,6 @@ vector<string> split(const string &s, char sep) {
} // strings::
#if 0
// context::
namespace context {
const error canceled = error::New("context canceled");
const error deadlineExceeded = error::New("deadline exceeded");
struct _Background : Context {
chan<structZ> done() {
return nil;
}
error err() {
return nil;
}
};
static _Background _bg;
Context* background() {
return &_bg; // NOTE nil is not valid in C++ (IContext* also carries vtab ptr)
}
} // context::
#endif
// xstrconv:: (strconv-like)
namespace xstrconv {
......
......@@ -53,37 +53,6 @@ using std::vector;
// nil is synonym for nullptr and NULL.
const nullptr_t nil = nullptr;
#if 0
// error mimics error from Go.
class error {
string _err;
public:
string Error() const;
error() {}
error(nullptr_t) {} // = nil
// == nil
bool operator==(nullptr_t) const {
return _err.empty();
}
bool operator!=(nullptr_t) const {
return !(*this==NULL);
}
// == error
bool operator==(const error &rhs) const {
return (_err == rhs._err);
}
bool operator!=(const error &rhs) const {
return !(*this==rhs);
}
// New creats error with text
static error New(const string &text);
};
#endif
// io::
namespace io {
......@@ -183,93 +152,9 @@ vector<string> split(const string &s, char sep);
} // strings::
#if 0
// context::
namespace context {
struct Context {
virtual chan<structZ> done() = 0;
virtual error err() = 0;
};
// XXX doc
Context* background();
// XXX doc
extern const error canceled;
extern const error deadlineExceeded;
} // context::
#endif
#if 0
interface(Context) {
ifunc(chan<structZ> done());
ifunc(error err());
};
I<io::Reader>(f)
// XXX wrap T* as IContext
template<typename T>
class Context : public IContext {
T *obj;
public:
Context(T *obj) : obj(obj) {}
chan<structZ> done() { return obj->done(); }
error err() { return obj->err(); }
};
#endif
// ---- misc ----
#if 0
#include <unordered_map>
#include <unordered_set>
// dict wraps unordered_map into ergonomic interface.
template<typename Key, typename Value>
struct dict : std::unordered_map<Key, Value> {
// has returns whether dict has element k.
bool has(const Key &k) const {
const dict &d = *this;
return d.find(k) != d.end();
}
// get implements `d[k] -> (v, ok)`.
tuple<Value, bool> get(const Key &k) const {
const dict &d = *this;
auto _ = d.find(k);
if (_ == d.end())
return make_tuple(Value(), false);
return make_tuple(_->second, true);
}
// pop implements `d[k] -> (v, ok); del d[k]`.
tuple<Value, bool> pop(const Key &k) {
dict &d = *this;
auto _ = d.find(k);
if (_ == d.end())
return make_tuple(Value(), false);
Value v = _->second;
d.erase(_);
return make_tuple(v, true);
}
};
// set wraps unordered_set into ergonomic interface.
template<typename Key>
struct set : std::unordered_set<Key> {
// has returns whether set has element k.
bool has(const Key &k) const {
const set &s = *this;
return s.find(k) != s.end();
}
};
#endif
// xstrconv::
namespace xstrconv {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment