Bug 1114701: Replace function pointers with function references, r=keeler

--HG--
extra : rebase_source : 350e7f8170f6b1176e46b829026e9ee27b3303e5
This commit is contained in:
Brian Smith 2014-12-23 12:43:25 -08:00
parent b2b9b81990
commit 899807654a
3 changed files with 37 additions and 28 deletions

View File

@ -31,7 +31,7 @@ namespace mozilla { namespace pkix {
// Similar to boost::scoped_ptr and std::unique_ptr. Does not support copying
// or assignment.
template <typename T, void (*Destroyer)(T*)>
template <typename T, void (&Destroyer)(T*)>
class ScopedPtr
{
public:
@ -73,28 +73,28 @@ protected:
void operator=(const ScopedPtr&) /* = delete */;
};
template <typename T, void(*Destroyer)(T*)>
template <typename T, void(&Destroyer)(T*)>
inline bool
operator==(T* a, const ScopedPtr<T, Destroyer>& b)
{
return a == b.get();
}
template <typename T, void(*Destroyer)(T*)>
template <typename T, void(&Destroyer)(T*)>
inline bool
operator==(const ScopedPtr<T, Destroyer>& a, T* b)
{
return a.get() == b;
}
template <typename T, void(*Destroyer)(T*)>
template <typename T, void(&Destroyer)(T*)>
inline bool
operator!=(T* a, const ScopedPtr<T, Destroyer>& b)
{
return a != b.get();
}
template <typename T, void(*Destroyer)(T*)>
template <typename T, void(&Destroyer)(T*)>
inline bool
operator!=(const ScopedPtr<T, Destroyer>& a, T* b)
{

View File

@ -74,11 +74,11 @@ template <typename R, typename P1, typename B1>
class Bind1
{
public:
typedef R (*F)(P1 &, B1 &);
Bind1(F f, B1 & b1) : f(f), b1(b1) { }
R operator()(P1 & p1) const { return f(p1, b1); }
typedef R (&F)(P1&, B1&);
Bind1(F f, B1& b1) : f(f), b1(b1) { }
R operator()(P1& p1) const { return f(p1, b1); }
private:
const F f;
F f;
B1& b1;
void operator=(const Bind1&) /*= delete*/;
};
@ -87,11 +87,11 @@ template <typename R, typename P1, typename B1, typename B2>
class Bind2
{
public:
typedef R (*F)(P1&, B1&, B2&);
typedef R (&F)(P1&, B1&, B2&);
Bind2(F f, B1& b1, B2& b2) : f(f), b1(b1), b2(b2) { }
R operator()(P1& p1) const { return f(p1, b1, b2); }
private:
const F f;
F f;
B1& b1;
B2& b2;
void operator=(const Bind2&) /*= delete*/;
@ -101,12 +101,12 @@ template <typename R, typename P1, typename B1, typename B2, typename B3>
class Bind3
{
public:
typedef R (*F)(P1&, B1, B2, B3&);
typedef R (&F)(P1&, B1, B2, B3&);
Bind3(F f, B1& b1, B2& b2, B3& b3)
: f(f), b1(b1), b2(b2), b3(b3) { }
R operator()(P1& p1) const { return f(p1, b1, b2, b3); }
private:
const F f;
F f;
B1& b1;
B2& b2;
B3& b3;
@ -118,12 +118,12 @@ template <typename R, typename P1, typename B1, typename B2, typename B3,
class Bind4
{
public:
typedef R (*F)(P1&, B1, B2, B3&, B4&);
typedef R (&F)(P1&, B1, B2, B3&, B4&);
Bind4(F f, B1& b1, B2& b2, B3& b3, B4& b4)
: f(f), b1(b1), b2(b2), b3(b3), b4(b4) { }
R operator()(P1& p1) const { return f(p1, b1, b2, b3, b4); }
private:
const F f;
F f;
B1& b1;
B2& b2;
B3& b3;
@ -136,12 +136,18 @@ template <typename R, typename C1, typename P1, typename P2, typename P3,
class BindToMemberFunction4
{
public:
// XXX: C++ doesn't have reference-to-member function, only
// pointer-to-member function, so we can't enforce the non-nullness of f
// using the type system.
typedef R (C1::*F)(P1&, P2&, P3, P4&);
BindToMemberFunction4(F f, C1* that) : f(f), that(that) { }
R operator()(P1& p1, P2& p2, P3 p3, P4& p4) const { return (that->*f)(p1, p2, p3, p4); }
BindToMemberFunction4(F f, C1& that) : f(f), that(that) { }
R operator()(P1& p1, P2& p2, P3 p3, P4& p4) const
{
return (that.*f)(p1, p2, p3, p4);
}
private:
const F f;
C1* const that;
C1& that;
void operator=(const BindToMemberFunction4&) /*= delete*/;
};
@ -150,12 +156,12 @@ template <typename R, typename P1, typename B1, typename B2, typename B3,
class Bind5
{
public:
typedef R (*F)(P1&, B1, B2, B3, B4, B5);
typedef R (&F)(P1&, B1, B2, B3, B4, B5);
Bind5(F f, B1 b1, B2 b2, B3 b3, B4 b4, B5 b5)
: f(f), b1(b1), b2(b2), b3(b3), b4(b4), b5(b5) { }
R operator()(P1& p1) const { return f(p1, b1, b2, b3, b4, b5); }
private:
const F f;
F f;
B1 b1;
B2 b2;
B3 b3;
@ -168,21 +174,21 @@ private:
template <typename R, typename P1, typename B1>
inline internal::Bind1<R, P1, B1>
bind(R (*f)(P1&, B1&), Placeholder1&, B1& b1)
bind(R (&f)(P1&, B1&), Placeholder1&, B1& b1)
{
return internal::Bind1<R, P1, B1>(f, b1);
}
template <typename R, typename P1, typename B1, typename B2>
inline internal::Bind2<R, P1, B1, B2>
bind(R (*f)(P1&, B1&, B2&), Placeholder1&, B1& b1, B2& b2)
bind(R (&f)(P1&, B1&, B2&), Placeholder1&, B1& b1, B2& b2)
{
return internal::Bind2<R, P1, B1, B2>(f, b1, b2);
}
template <typename R, typename P1, typename B1, typename B2, typename B3>
inline internal::Bind3<R, P1, const B1, const B2, B3>
bind(R (*f)(P1&, B1, B2, B3&), Placeholder1&, const B1& b1, const B2& b2,
bind(R (&f)(P1&, B1, B2, B3&), Placeholder1&, const B1& b1, const B2& b2,
B3& b3)
{
return internal::Bind3<R, P1, const B1, const B2, B3>(f, b1, b2, b3);
@ -191,17 +197,20 @@ bind(R (*f)(P1&, B1, B2, B3&), Placeholder1&, const B1& b1, const B2& b2,
template <typename R, typename P1, typename B1, typename B2, typename B3,
typename B4>
inline internal::Bind4<R, P1, const B1, const B2, B3, B4>
bind(R (*f)(P1&, B1, B2, B3&, B4&), Placeholder1&, const B1& b1, const B2& b2,
bind(R (&f)(P1&, B1, B2, B3&, B4&), Placeholder1&, const B1& b1, const B2& b2,
B3& b3, B4& b4)
{
return internal::Bind4<R, P1, const B1, const B2, B3, B4>(f, b1, b2, b3, b4);
}
// XXX: C++ doesn't have reference-to-member function, only
// pointer-to-member function, so we can't enforce the non-nullness of f
// using the type system.
template <typename R, typename C1, typename P1, typename P2, typename P3,
typename P4>
inline internal::BindToMemberFunction4<R, C1, P1, P2, P3, P4>
bind(R (C1::*f)(P1&, P2&, P3, P4&), C1* that, Placeholder1&, Placeholder2&,
Placeholder3, Placeholder4&)
bind(R (C1::*f)(P1&, P2&, P3, P4&), C1& that, Placeholder1&,
Placeholder2&, Placeholder3, Placeholder4&)
{
return internal::BindToMemberFunction4<R, C1, P1, P2, P3, P4>(f, that);
}
@ -209,7 +218,7 @@ bind(R (C1::*f)(P1&, P2&, P3, P4&), C1* that, Placeholder1&, Placeholder2&,
template <typename R, typename P1, typename B1, typename B2, typename B3,
typename B4, typename B5>
inline internal::Bind5<R, P1, B1, B2, B3, B4, B5&>
bind(R (*f)(P1&, B1, B2, B3, B4, B5&), Placeholder1&, B1 b1, B2 b2, B3 b3,
bind(R (&f)(P1&, B1, B2, B3, B4, B5&), Placeholder1&, B1 b1, B2 b2, B3 b3,
B4 b4, B5& b5)
{
return internal::Bind5<R, P1, B1, B2, B3, B4, B5&>(f, b1, b2, b3, b4, b5);

View File

@ -141,7 +141,7 @@ BackCert::Init()
}
rv = der::OptionalExtensions(tbsCertificate, CSC | 3,
bind(&BackCert::RememberExtension, this, _1,
bind(&BackCert::RememberExtension, *this, _1,
_2, _3, _4));
if (rv != Success) {
return rv;