Cant understand cpp snippet

0 votes

This snippet is lifted from bitcoin code base.

struct CombinerAll
{
    typedef bool result_type;

    template<typename I>
    bool operator()(I first, I last) const
    {
        while (first != last) {
            if (!(*first)) return false;
            ++first;
        }
        return true;
    }
};

This gets used here

boost::signals2::signal<bool (CNode*), CombinerAll> ProcessMessages;

I dont understand what it is for. Need help

Aug 27, 2018 in Blockchain by digger
• 26,550 points
24 views

1 answer to this question.

0 votes

From the function:

        if (!(*first)) return false;

If any of the elements in the range [first, last) evaluate to false when the pointer/iterator/object is dereferenced, the function returns false. Otherwise, it returns true.

Example test code:

int main()
{
   std::string sa = "abc";

   std::vector<int> va = {1, 1, 1};
   std::vector<int> vb = {1, 0, 2};

   std::cout << std::boolalpha;
   std::cout << CombinerAll()(sa.begin(), sa.end()) << std::endl;

   std::cout << CombinerAll()(va.begin(), va.end()) << std::endl;
   std::cout << CombinerAll()(vb.begin(), vb.end()) << std::endl;

   return 0;
}

Output:

true
true
false
answered Aug 27, 2018 by slayer
• 29,170 points

Related Questions In Blockchain

+1 vote
1 answer

Blockchain declining my API key and I cannot understand why.

It's quite easy. Request the API key using ...READ MORE

answered Apr 3, 2018 in Blockchain by Christine
• 15,790 points
232 views
0 votes
1 answer

Can't import "blockchain.info" to Node.js.. Need help.

Aurelia is a client-side framework and blockchain ...READ MORE

answered Jun 27, 2018 in Blockchain by Omkar
• 67,620 points
70 views
0 votes
1 answer

Can't install remote HTTP chaincode

Fabric 1.0 does not support remote paths ...READ MORE

answered Jun 27, 2018 in Blockchain by Omkar
• 67,620 points
39 views
0 votes
1 answer

IBM Blockchain cant retrieving multiple rows from table

You can not use the older implementation ...READ MORE

answered Jul 5, 2018 in Blockchain by digger
• 26,550 points
23 views
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
80 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
155 views
0 votes
1 answer
0 votes
1 answer

Cant decode hex sting into decimal. Getting TypeError.

On the line where it shows error, ...READ MORE

answered Jul 6, 2018 in Blockchain by slayer
• 29,170 points
364 views
0 votes
1 answer

Can’t find value for key while using CouchDB for Fabric.

In the output you have mentioned: {   "id": ...READ MORE

answered Jul 31, 2018 in Blockchain by slayer
• 29,170 points
200 views