Remove BisonWrap, which was a Ptr-specific feature (#836)

This commit is contained in:
Jon Meow
2021-09-20 13:51:20 -07:00
committed by GitHub
parent fbb0aa729b
commit 9edb2459fd
3 changed files with 29 additions and 82 deletions
-44
View File
@@ -1,44 +0,0 @@
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#ifndef EXECUTABLE_SEMANTICS_SYNTAX_BISON_WRAP_H_
#define EXECUTABLE_SEMANTICS_SYNTAX_BISON_WRAP_H_
#include <optional>
#include "common/check.h"
namespace Carbon {
// Bison requires that types be default initializable for use with its variant
// semantics. This wraps arbitrary types to support a default constructor, while
// still requiring they be properly initialized.
template <typename T>
class BisonWrap {
public:
// Assigning a value initializes the wrapper.
BisonWrap& operator=(T&& rhs) {
val = std::move(rhs);
return *this;
}
// Support transparent conversion to the wrapped type.
operator T() { return Release(); }
// Deliberately releases the contained value. Errors if not initialized.
// Called directly in parser.ypp when releasing pairs.
auto Release() -> T {
CHECK(val.has_value());
T ret = std::move(*val);
val.reset();
return ret;
}
private:
std::optional<T> val;
};
} // namespace Carbon
#endif // EXECUTABLE_SEMANTICS_SYNTAX_BISON_WRAP_H_