1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/public/Vector.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,66 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- 1.5 + * vim: set ts=8 sts=4 et sw=4 tw=99: 1.6 + * This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#ifndef js_Vector_h 1.11 +#define js_Vector_h 1.12 + 1.13 +#include "mozilla/Vector.h" 1.14 + 1.15 +/* Silence dire "bugs in previous versions of MSVC have been fixed" warnings */ 1.16 +#ifdef _MSC_VER 1.17 +#pragma warning(push) 1.18 +#pragma warning(disable:4345) 1.19 +#endif 1.20 + 1.21 +namespace js { 1.22 + 1.23 +class TempAllocPolicy; 1.24 + 1.25 +// If we had C++11 template aliases, we could just use this: 1.26 +// 1.27 +// template <typename T, 1.28 +// size_t MinInlineCapacity = 0, 1.29 +// class AllocPolicy = TempAllocPolicy> 1.30 +// using Vector = mozilla::Vector<T, MinInlineCapacity, AllocPolicy>; 1.31 +// 1.32 +// ...and get rid of all the CRTP madness in mozilla::Vector(Base). But we 1.33 +// can't because compiler support's not up to snuff. (Template aliases are in 1.34 +// gcc 4.7 and clang 3.0 and are expected to be in MSVC 2013.) Instead, have a 1.35 +// completely separate class inheriting from mozilla::Vector, and throw CRTP at 1.36 +// the problem til things work. 1.37 +// 1.38 +// This workaround presents a couple issues. First, because js::Vector is a 1.39 +// distinct type from mozilla::Vector, overload resolution, method calls, etc. 1.40 +// are affected. *Hopefully* this won't be too bad in practice. (A bunch of 1.41 +// places had to be fixed when mozilla::Vector was introduced, but it wasn't a 1.42 +// crazy number.) Second, mozilla::Vector's interface has to be made subclass- 1.43 +// ready via CRTP -- or rather, via mozilla::VectorBase, which basically no one 1.44 +// should use. :-) Third, we have to redefine the constructors and the non- 1.45 +// inherited operators. Blech. Happily there aren't too many of these, so it 1.46 +// isn't the end of the world. 1.47 + 1.48 +template <typename T, 1.49 + size_t MinInlineCapacity = 0, 1.50 + class AllocPolicy = TempAllocPolicy> 1.51 +class Vector 1.52 + : public mozilla::VectorBase<T, 1.53 + MinInlineCapacity, 1.54 + AllocPolicy, 1.55 + Vector<T, MinInlineCapacity, AllocPolicy> > 1.56 +{ 1.57 + typedef typename mozilla::VectorBase<T, MinInlineCapacity, AllocPolicy, Vector> Base; 1.58 + 1.59 + public: 1.60 + Vector(AllocPolicy alloc = AllocPolicy()) : Base(alloc) {} 1.61 + Vector(Vector &&vec) : Base(mozilla::Move(vec)) {} 1.62 + Vector &operator=(Vector &&vec) { 1.63 + return Base::operator=(mozilla::Move(vec)); 1.64 + } 1.65 +}; 1.66 + 1.67 +} // namespace js 1.68 + 1.69 +#endif /* js_Vector_h */