#include <functional>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>

struct buf_rx
{
    using callback_type = std::function<void(std::string)> ;

    void receive(std::istringstream in)
    {
        std::string word;
        while (in >> word)
            for (auto func : _cb)
                func(word);
    }

    void register_cb(callback_type cb_func)
    {
        _cb.push_back(cb_func);
    }

private:
    std::vector<callback_type> _cb;
};

void string_processor(const std::string& s)
{
    std::cout << "string_processor: " << s << '\n';
}

struct some_type
{
    some_type() :_id(id++) {}

    void process_string(const std::string& s) {
        std::cout << "some_type (" << _id << "): " << s << '\n';
    }

private:
    static unsigned id;
    unsigned _id;
};

unsigned some_type::id = 0;

int main()
{
    some_type a;
    some_type b;

    buf_rx buffer;
    buffer.register_cb(string_processor);
    buffer.register_cb([&](std::string s) {a.process_string(s); });
    buffer.register_cb([&](std::string s) {b.process_string(s); });

    buffer.receive(std::istringstream { "a b c d e" });
}