<commit_before>/*-
 * This file is part of CXX Experiments.
 *
 * CXX Experiments is free software. See AUTHORS and LICENSE for more
 * information on the copying conditions.
 */

///
/// \file src/callbacks.cpp
/// \brief Example with callbacks
///

#include "pointer.hpp"
#include "transport.hpp"

#include <iostream>

using namespace cxx_experiments;

class MyTransport : public Transport {
public:
  MyTransport(int fd = -1) : Transport(fd) {
    std::cout << "Construct " << this << "\n";
  }

  ~MyTransport() { std::cout << "Destruct " << this << "\n"; }

  void emit_connect() {
    std::cout << "Connect " << this << "\n";
    Transport::emit_connect();
  }
};

static void create_transport() {
  auto transport = make<MyTransport>(12345);
  transport->on_connect([transport]() {
    //transport.close();
  });
  transport->emit_connect();
}

int main() { create_transport(); }
<commit_msg>Surprise: only const methods can be invoked within the closure<commit_after>/*-
 * This file is part of CXX Experiments.
 *
 * CXX Experiments is free software. See AUTHORS and LICENSE for more
 * information on the copying conditions.
 */

///
/// \file src/callbacks.cpp
/// \brief Example with callbacks
///

#include "pointer.hpp"
#include "transport.hpp"

#include <iostream>

using namespace cxx_experiments;

class MyTransport : public Transport {
public:
  MyTransport(int fd = -1) : Transport(fd) {
    std::cout << "Construct " << this << "\n";
  }

  ~MyTransport() { std::cout << "Destruct " << this << "\n"; }

  void emit_connect() {
    std::cout << "Connect " << this << "\n";
    Transport::emit_connect();
  }
};

static void create_transport() {
  auto transport = make<MyTransport>(12345);
  transport->on_connect([transport]() {
    transport->close();
  });
  transport->emit_connect();
}

int main() { create_transport(); }

{'fraction_non_alphanumeric': 0.1646803900325027, 'fraction_numerical': 0.0065005417118093175, 'mean_word_length': 3.6175, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4507843', 'n_tokens_mistral': 583, 'n_tokens_neox': 564, 'n_words': 161}