From d8f710cedd62c1d28beee15d7dc3d31ddd148437 Mon Sep 17 00:00:00 2001 From: tsepez Date: Sun, 20 Nov 2016 01:00:29 -0800 Subject: Provide perfect-forwarding in CPDF_Object templates. We'll hit this issue when we try to make CPDF_stream ctors take other unique pointers, for example. Review-Url: https://codereview.chromium.org/2513613003 --- core/fpdfapi/parser/cpdf_array.h | 33 +++++++++++++---------- core/fpdfapi/parser/cpdf_dictionary.h | 12 +++++---- core/fpdfapi/parser/cpdf_indirect_object_holder.h | 12 +++++---- 3 files changed, 33 insertions(+), 24 deletions(-) diff --git a/core/fpdfapi/parser/cpdf_array.h b/core/fpdfapi/parser/cpdf_array.h index 125cb4cbf8..0b16f7f21b 100644 --- a/core/fpdfapi/parser/cpdf_array.h +++ b/core/fpdfapi/parser/cpdf_array.h @@ -10,6 +10,7 @@ #include #include #include +#include #include #include "core/fpdfapi/parser/cpdf_indirect_object_holder.h" @@ -58,39 +59,43 @@ class CPDF_Array : public CPDF_Object { // a ByteStringPool. template typename std::enable_if::value, T*>::type AddNew( - Args... args) { - return static_cast(Add(pdfium::MakeUnique(args...))); + Args&&... args) { + return static_cast( + Add(pdfium::MakeUnique(std::forward(args)...))); } template typename std::enable_if::value, T*>::type AddNew( - Args... args) { - return static_cast(Add(pdfium::MakeUnique(m_pPool, args...))); + Args&&... args) { + return static_cast( + Add(pdfium::MakeUnique(m_pPool, std::forward(args)...))); } template typename std::enable_if::value, T*>::type SetNewAt( size_t index, - Args... args) { - return static_cast(SetAt(index, pdfium::MakeUnique(args...))); + Args&&... args) { + return static_cast( + SetAt(index, pdfium::MakeUnique(std::forward(args)...))); } template typename std::enable_if::value, T*>::type SetNewAt( size_t index, - Args... args) { - return static_cast( - SetAt(index, pdfium::MakeUnique(m_pPool, args...))); + Args&&... args) { + return static_cast(SetAt( + index, pdfium::MakeUnique(m_pPool, std::forward(args)...))); } template typename std::enable_if::value, T*>::type InsertNewAt( size_t index, - Args... args) { - return static_cast(InsertAt(index, pdfium::MakeUnique(args...))); + Args&&... args) { + return static_cast( + InsertAt(index, pdfium::MakeUnique(std::forward(args)...))); } template typename std::enable_if::value, T*>::type InsertNewAt( size_t index, - Args... args) { - return static_cast( - InsertAt(index, pdfium::MakeUnique(m_pPool, args...))); + Args&&... args) { + return static_cast(InsertAt( + index, pdfium::MakeUnique(m_pPool, std::forward(args)...))); } void RemoveAt(size_t index, size_t nCount = 1); diff --git a/core/fpdfapi/parser/cpdf_dictionary.h b/core/fpdfapi/parser/cpdf_dictionary.h index 5d333808b9..13cbdcf7ac 100644 --- a/core/fpdfapi/parser/cpdf_dictionary.h +++ b/core/fpdfapi/parser/cpdf_dictionary.h @@ -10,6 +10,7 @@ #include #include #include +#include #include "core/fpdfapi/parser/cpdf_object.h" #include "core/fxcrt/cfx_string_pool_template.h" @@ -70,15 +71,16 @@ class CPDF_Dictionary : public CPDF_Object { template typename std::enable_if::value, T*>::type SetNewFor( const CFX_ByteString& key, - Args... args) { - return static_cast(SetFor(key, pdfium::MakeUnique(args...))); + Args&&... args) { + return static_cast( + SetFor(key, pdfium::MakeUnique(std::forward(args)...))); } template typename std::enable_if::value, T*>::type SetNewFor( const CFX_ByteString& key, - Args... args) { - return static_cast( - SetFor(key, pdfium::MakeUnique(m_pPool, args...))); + Args&&... args) { + return static_cast(SetFor( + key, pdfium::MakeUnique(m_pPool, std::forward(args)...))); } // Convenience functions to convert native objects to array form. diff --git a/core/fpdfapi/parser/cpdf_indirect_object_holder.h b/core/fpdfapi/parser/cpdf_indirect_object_holder.h index a78e6663b3..1b174d8b62 100644 --- a/core/fpdfapi/parser/cpdf_indirect_object_holder.h +++ b/core/fpdfapi/parser/cpdf_indirect_object_holder.h @@ -10,6 +10,7 @@ #include #include #include +#include #include "core/fpdfapi/parser/cpdf_object.h" #include "core/fxcrt/cfx_string_pool_template.h" @@ -34,14 +35,15 @@ class CPDF_IndirectObjectHolder { // handle objects that can intern strings from our ByteStringPool. template typename std::enable_if::value, T*>::type NewIndirect( - Args... args) { - return static_cast(AddIndirectObject(pdfium::MakeUnique(args...))); + Args&&... args) { + return static_cast( + AddIndirectObject(pdfium::MakeUnique(std::forward(args)...))); } template typename std::enable_if::value, T*>::type NewIndirect( - Args... args) { - return static_cast( - AddIndirectObject(pdfium::MakeUnique(m_pByteStringPool, args...))); + Args&&... args) { + return static_cast(AddIndirectObject( + pdfium::MakeUnique(m_pByteStringPool, std::forward(args)...))); } // Takes ownership of |pObj|, returns unowned pointer to it. -- cgit v1.2.3