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,600 points
89 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,240 points

Related Questions In Blockchain

+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,090 points
151 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 7, 2018 in Blockchain by Johnathon
• 9,090 points
26 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 16, 2018 in Blockchain by Johnathon
• 9,090 points
118 views
0 votes
1 answer
0 votes
1 answer

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

yes all are over TCP/IP connections secured by TLS encryption in hashgraph architecture-hashgraph, ...READ MORE

answered Aug 6, 2018 in Blockchain by ariaholic
• 7,340 points
103 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,810 points
188 views
0 votes
1 answer
0 votes
1 answer