How to use std iterator with basic type uint8 t

0 votes

I was going through a code on https://github.com/bitcoin/bitcoin/blob/master/src/uint256.cpp#L23

that traverses array of uint8_t using std::reverse_iterator<const uint8_t*>.

The code snippet is as follows:

#include <stdint.h>

#include <iterator>

#include <iostream>


using namespace std;

uint8_t data[8] = {0, 1, 2, 3, 4, 5, 6, 7};


template<typename T>

void HexStr(const T itbegin, const T itend)

{

    for (T it = itbegin; it < itend; ++it)

    {

        cout << +*it << " ";

    }

    cout << endl;

}


int main()

{

    HexStr(reverse_iterator<const uint8_t*>(data + sizeof(data)),

           reverse_iterator<const uint8_t*>(data));


    return 0;

}

Why I can not I do the same thing using using a regular iterator (std::iterator<const uint8_t*>.

When I tried, I get the following error:

error: wrong number of template arguments (1, should be at least 2).

Can somebody tell me why this is happening?

Aug 24, 2018 in Blockchain by digger
• 26,740 points
1,478 views

1 answer to this question.

0 votes
std::reverse_iterator takes the original iterator type as template parameter.

Thus the type you're looking for is const uint8_t*, not std::iterator<const uint8_t*>
answered Aug 24, 2018 by slayer
• 29,370 points

Related Questions In Blockchain

0 votes
1 answer
+1 vote
1 answer

Hyperledger - How can I use transaction certificates to enforce privacy?

The transaction certificates don't actually address privacy ...READ MORE

answered Apr 17, 2018 in Blockchain by Perry
• 17,100 points
925 views
0 votes
1 answer

How feasible is it to use one way cryptographic hash function?

you can use the ouput hash function ...READ MORE

answered May 8, 2018 in Blockchain by Johnathon
• 9,090 points
627 views
0 votes
1 answer

How do I use hyperledger fabric blockchain to build my own application?

To use fabric I would recommend you ...READ MORE

answered May 17, 2018 in Blockchain by Johnathon
• 9,090 points
1,089 views
+1 vote
1 answer

Protocols used in a distributed/dlt system for the nodes to establish communication

yes all are over TCP/IP connections secured ...READ MORE

answered Aug 6, 2018 in Blockchain by aryya
• 7,460 points
1,460 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
1,947 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,470 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP