Add initializer list constructor for hierarchical names
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
parent
f18149934b
commit
33e8e4af23
3 changed files with 20 additions and 0 deletions
|
@ -61,9 +61,16 @@ static void tst2() {
|
|||
std::cout << "n1.hash(): " << n1.hash() << "\n";
|
||||
}
|
||||
|
||||
static void tst3() {
|
||||
name n{"foo", "bla", "tst"};
|
||||
std::cout << n << "\n";
|
||||
lean_assert(n == name(name(name("foo"), "bla"), "tst"));
|
||||
}
|
||||
|
||||
int main() {
|
||||
continue_on_violation(true);
|
||||
tst1();
|
||||
tst2();
|
||||
tst3();
|
||||
return has_violations() ? 1 : 0;
|
||||
}
|
||||
|
|
|
@ -124,6 +124,18 @@ name::name(name && other):m_ptr(other.m_ptr) {
|
|||
other.m_ptr = nullptr;
|
||||
}
|
||||
|
||||
name::name(std::initializer_list<char const *> const & l):name() {
|
||||
if (l.size() == 0) {
|
||||
return;
|
||||
} else {
|
||||
auto it = l.begin();
|
||||
*this = name(*it);
|
||||
++it;
|
||||
for (; it != l.end(); ++it)
|
||||
*this = name(*this, *it);
|
||||
}
|
||||
}
|
||||
|
||||
name::~name() {
|
||||
if (m_ptr)
|
||||
m_ptr->dec_ref();
|
||||
|
|
|
@ -28,6 +28,7 @@ public:
|
|||
name(name const & prefix, unsigned k);
|
||||
name(name const & other);
|
||||
name(name && other);
|
||||
name(std::initializer_list<char const *> const & l);
|
||||
~name();
|
||||
name & operator=(name const & other);
|
||||
name & operator=(name && other);
|
||||
|
|
Loading…
Reference in a new issue