forked from 0ad/0ad
Replace use of safe bool by explicit bool operator.
This was SVN commit r16228.
This commit is contained in:
parent
4c1903500b
commit
123bab6793
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2012 Wildfire Games.
|
||||
/* Copyright (C) 2015 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -57,12 +57,6 @@ class CmpPtr
|
||||
private:
|
||||
T* m;
|
||||
|
||||
// "Safe Bool Idiom" based on http://www.artima.com/cppsource/safebool.html
|
||||
// to allow "if (cmp)" and "if (!cmp)" etc, without also allowing "int i = cmp"
|
||||
// or "if (cmp1 == cmp2)" etc.
|
||||
typedef void (CmpPtr::*bool_type)() const;
|
||||
void this_type_does_not_support_comparisons() const {}
|
||||
|
||||
public:
|
||||
CmpPtr(const CSimContext& context, entity_id_t ent)
|
||||
{
|
||||
@ -85,24 +79,10 @@ public:
|
||||
|
||||
T* operator->() { return m; }
|
||||
|
||||
operator bool_type() const
|
||||
explicit operator bool() const
|
||||
{
|
||||
return (m != NULL) ? &CmpPtr::this_type_does_not_support_comparisons : 0;
|
||||
return m != NULL;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T, typename U>
|
||||
bool operator!=(const CmpPtr<T>& lhs, const U& UNUSED(rhs))
|
||||
{
|
||||
lhs.this_type_does_not_support_comparisons();
|
||||
return false;
|
||||
}
|
||||
|
||||
template<typename T, typename U>
|
||||
bool operator==(const CmpPtr<T>& lhs, const U& UNUSED(rhs))
|
||||
{
|
||||
lhs.this_type_does_not_support_comparisons();
|
||||
return false;
|
||||
}
|
||||
|
||||
#endif // INCLUDED_CMPPTR
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2014 Wildfire Games.
|
||||
/* Copyright (C) 2015 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -51,8 +51,6 @@ private:
|
||||
void inc_ref();
|
||||
void dec_ref();
|
||||
T* ptr;
|
||||
typedef void (AtSmartPtr::*bool_type)() const;
|
||||
void this_type_does_not_support_comparisions() const {}
|
||||
public:
|
||||
// Constructors
|
||||
AtSmartPtr() : ptr(NULL) {}
|
||||
@ -68,23 +66,10 @@ public:
|
||||
//operator AtSmartPtr<const T> () { return AtSmartPtr<const T>(ptr); } // (actually provided by ConstCastHelper)
|
||||
// Override ->
|
||||
T* operator->() const { return ptr; }
|
||||
// Test whether the pointer is pointing to anything using safe bool
|
||||
operator bool_type() const { return (ptr!=NULL) == true ? &AtSmartPtr::this_type_does_not_support_comparisions : 0; }
|
||||
// Test whether the pointer is pointing to anything
|
||||
explicit operator bool() const { return ptr != NULL; }
|
||||
};
|
||||
|
||||
template<typename T, typename U>
|
||||
bool operator!=(const AtSmartPtr<T>& lhs, const U&)
|
||||
{
|
||||
lhs.this_type_does_not_support_comparisions();
|
||||
return false;
|
||||
}
|
||||
template<typename T, typename U>
|
||||
bool operator==(const AtSmartPtr<T>& lhs, const U&)
|
||||
{
|
||||
lhs.this_type_does_not_support_comparisions();
|
||||
return false;
|
||||
}
|
||||
|
||||
template<class ConstSmPtr, class T>
|
||||
ConstCastHelper<ConstSmPtr, T>::operator ConstSmPtr ()
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2014 Wildfire Games.
|
||||
/* Copyright (C) 2015 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -89,7 +89,7 @@ AtIter& AtIter::operator ++ ()
|
||||
|
||||
bool AtIter::defined() const
|
||||
{
|
||||
return p;
|
||||
return (bool)p;
|
||||
}
|
||||
|
||||
bool AtIter::hasContent() const
|
||||
|
Loading…
Reference in New Issue
Block a user