View Issue Details

IDProjectCategoryView StatusLast Update
0002749OpenFOAMBugpublic2017-11-06 09:58
Reporterchaohsiung Assigned Tohenry  
PrioritynormalSeverityminorReproducibilityN/A
Status resolvedResolutionfixed 
Fixed 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.

Activities

henry

2017-11-02 16:46

manager   ~0008984

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.

henry

2017-11-06 09:58

manager   ~0009003

Resolved by commit 36dcb28511744d8d9fa4e89c1e27dc06b57fd440

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