[odb-users] odb::result<T> does not contain members
"const_iterator" and "end () const".
Jeroen N. Witmond [Bahco]
jnw at xs4all.nl
Fri Feb 27 12:47:25 EST 2015
Hi Boris,
Boris Kolpackov wrote:
> Hi Jeroen,
>
> Jeroen N. Witmond [Bahco] <jnw at xs4all.nl> writes:
>
>> While experimenting with ODB I noticed that odb::result<T> does not
>> contain members "const_iterator" and "end () const".
>
> Result is a stream-like object and result::iterator is an input
> iterator. In this light, it doesn't make much sense to have a
> const_iterator since advancing the iterator changes the result.
>
>
>> The compiler noticed it, anyway. :-)
>
> Can you show the code fragment that triggered it?
#include <iostream>
#include <odb/database.hxx>
/* This class should be in a separate .hpp file and contain some
* #pragmas. The generated odb.hxx file should be included. However,
* the current content is sufficient to demonstrate the use of const.
*/
class FourPoint
{
public:
double latitude;
};
typedef odb::result<FourPoint> result;
inline std::ostream& operator<<(std::ostream& out, const result& val)
{
for (result::const_iterator i (val.begin ()); i != val.end (); ++i)
out << *i << std::endl;
return out;
}
This code results in the following errors:
noconstiter.cpp: In function std::ostream& operator<<(std::ostream&,
const result&):
noconstiter.cpp:18:8: error: const_iterator is not a member of result
{aka odb::result<FourPoint>}
noconstiter.cpp:18:31: error: expected ; before i
noconstiter.cpp:18:49: error: i was not declared in this scope
noconstiter.cpp:18:63: error: no matching function for call to
odb::result<FourPoint>::end() const
noconstiter.cpp:18:63: note: candidate is:
In file included from /usr/local/include/odb/prepared-query.hxx:12:0,
from /usr/local/include/odb/database.hxx:27,
from noconstiter.cpp:2:
/usr/local/include/odb/result.hxx:176:5: note: odb::result<T>::iterator
odb::result<T>::end() [with T = FourPoint; odb::result<T>::iterator =
odb::result_iterator<FourPoint, (odb::class_kind)2u>] <near match>
/usr/local/include/odb/result.hxx:176:5: note: no known conversion for
implicit this parameter from const result* {aka const
odb::result<FourPoint>*} to odb::result<FourPoint>*
Removing all consts in this operator<< results in working code.
Regards,
Jeroen.
More information about the odb-users
mailing list