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
• 27,620 points
46 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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,040 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
• 16,450 points
88 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,050 points
12 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,050 points
51 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,320 points
45 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
77 views
0 votes
1 answer
0 votes
1 answer

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.