2017-11-24 09:10 GMT

View Issue Details Jump to Notes ]
IDProjectCategoryView StatusLast Update
0002749OpenFOAM[All Projects] Bugpublic2017-11-06 09:58
Reporterchaohsiung 
Assigned Tohenry 
PrioritynormalSeverityminorReproducibilityN/A
StatusresolvedResolutionfixed 
Product Version 
Target VersionFixed in Versiondev 
Summary0002749: iterator operator
DescriptionDo we really need this sizeof(T*)? iterx.ptr_ is already defined as T**.

//-----------------------
// UPtrListI.H
template<class T>
inline Foam::label Foam::operator-
(
    const typename UPtrList<T>::const_iterator& iter1,
    const typename UPtrList<T>::const_iterator& iter2
)
{
    return (iter1.ptr_ - iter2.ptr_)/sizeof(T*);
}


//-------------------------
I've tested the revised operator by removing the sizeof(T*):

int main()
{
    UPtrList<int> ptrL(10);

    UPtrList<int>::iterator it1 = ptrL.begin();
    UPtrList<int>::iterator it2 = ptrL.end();

    std::cout << "sizeof(int*):\t" << sizeof(int*) << std::endl;
    std::cout << "it2-it1:\t" << it2-it1 << std::endl;
    std::cout << "(it2-it1)/sizeof(int*):\t" << (it2-it1)/sizeof(int*)
              << std::endl;

    return 0;
}


//----------------------------
The result is

sizeof(int*): 8
it2-it1: 10
(it2-it1)/sizeof(int*): 1



TagsNo tags attached.
Attached Files

-Relationships
+Relationships

-Notes

~0008984

henry (manager)

Which OpenFOAM version, OS and compiler are you using?

When compiling your example with OpenFOAM-dev, gcc-7.2.1 or clang-4.0.1

I get error messages of the form "couldn't deduce template parameter ‘T’" and it does not compile.

~0009003

henry (manager)

Resolved by commit 36dcb28511744d8d9fa4e89c1e27dc06b57fd440
+Notes

-Issue History
Date Modified Username Field Change
2017-11-02 16:13 chaohsiung New Issue
2017-11-02 16:46 henry Note Added: 0008984
2017-11-06 09:58 henry Assigned To => henry
2017-11-06 09:58 henry Status new => resolved
2017-11-06 09:58 henry Resolution open => fixed
2017-11-06 09:58 henry Fixed in Version => dev
2017-11-06 09:58 henry Note Added: 0009003
+Issue History