Commit 73db250c authored by Robert Bradshaw's avatar Robert Bradshaw

Add support for vector[bool].at(...)

parent 338d5c44
...@@ -3478,6 +3478,19 @@ class CppClassType(CType): ...@@ -3478,6 +3478,19 @@ class CppClassType(CType):
if self.namespace is not None: if self.namespace is not None:
specialized.namespace = self.namespace.specialize(values) specialized.namespace = self.namespace.specialize(values)
specialized.scope = self.scope.specialize(values, specialized) specialized.scope = self.scope.specialize(values, specialized)
if self.cname == 'std::vector':
# vector<bool> is special cased in the C++ standard, and its
# accessors do not necessarily return references to the underlying
# elements (which may be bit-packed).
# http://www.cplusplus.com/reference/vector/vector-bool/
# Here we pretend that the various methods return bool values
# (as the actual returned values are coercable to such, and
# we don't support call expressions as lvalues).
T = values[self.templates[0]]
if T.empty_declaration_code() == 'bool':
for bit_ref_returner in ('at', 'back', 'front'):
if bit_ref_returner in specialized.scope.entries:
specialized.scope.entries[bit_ref_returner].type.return_type = T
return specialized return specialized
def deduce_template_params(self, actual): def deduce_template_params(self, actual):
......
...@@ -172,7 +172,8 @@ def test_bool_vector_get_set(): ...@@ -172,7 +172,8 @@ def test_bool_vector_get_set():
# Test access. # Test access.
assert not v[0], v assert not v[0], v
assert v[1], v assert v[1], v
# assert v.at(0) assert not v.at(0), v
assert v.at(1), v
v[0] = True v[0] = True
v[1] = False v[1] = False
assert <object>v == [True, False, True, True, True] assert <object>v == [True, False, True, True, True]
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