Augment DynamicConverter's is_container check
authorNicholas Ormrod <njormrod@fb.com>
Tue, 6 Nov 2012 17:22:57 +0000 (09:22 -0800)
committerJordan DeLong <jdelong@fb.com>
Sun, 16 Dec 2012 22:43:10 +0000 (14:43 -0800)
commitc9f168a1db1138aeb73bfc87b34e75e03f414c91
tree430f39519e8fe5a263aab79343c3e6e5e8582dfe
parent96bd762fc047066ccad4f00dba4de95abadfae98
Augment DynamicConverter's is_container check

Summary:
DynamicConverter uses some simple heuristics to determine if a
class is a container. One of those tests was to check that the
constructor 'template <class Iterator> [container-name](Iterator first,
Iterator last)' was present. That test was performed by checking if the
class could be constructed by two parameters of some dummy class.

However, it is possible to restrict the template parameter such that it
only accepts iterators, and not any arbitrary dummy class. This would be
useful, for example, to solve overload ambiguity with constructors like
'vector(const T& val, size_type n)', where T and size_type are the same
(see N3337 23.2.3 item 14). It also (I believe) produces more meaningful
compiler errors when a non-iterator is supplied, since it errors at the
function callsite instead of inside the constructor itself.

The new FBVector implementation uses such a feature, and so checking for
[container-name](dummy, dummy) will fail. Hence the dummy class has been
upgraded to reverse_iterator<T*>, a valid iterator class which almost
certainly does not have a specialized contructor in any class (and hence
will not cause any visible change in class_is_container's value).

Test Plan:
Run DynamicConverterTest; it has tests for the correctness of
class_is_container.

Reviewed By: delong.j@fb.com

FB internal diff: D620607
folly/DynamicConverter.h