6 Mart 2017 Pazartesi

variant make_variant_over

Giriş
Bu metod bir MPL Sequence alır ve variant döndürür. Şöyle yaparız.
#include<boost/variant.hpp>

using List = boost::mpl::list<double, int>;
using Variant = boost::make_variant_over<List>::type;

range

make_iterator_range metodu - vector
Şu satırı dahil ederiz.
#include <boost/range/iterator_range.hpp>
Şöyle yaparız.
const std::vector<int> v {1, 2, 3};

const auto range = boost::make_iterator_range(v);

std::copy(std::crbegin(range),
          std::crend(range),
          std::ostream_iterator<int> {std::cout, " "});
make_iterator_range metodu - directory_iterator + directory_iterator
Örnek 1 - for döngüsü
Şöyle yaparız.
for (fs::path p : boost::make_iterator_range(fs::directory_iterator("."), {})) {
  if (!fs::is_regular_file(p) || p.extension() != ".txt")
    continue;

  std::ifstream infile(p.string()); // Read file line by line
  while (std::getline(infile, line)) {
    if (boost::regex_search(line, result, pattern)) {
      std::cout << "\t" << result.str() << "\n";
    }
  }
}    
Örnek 2 - lambda
Şöyle yaparız.
path const p(".");

auto list = [=] { return boost::make_iterator_range(directory_iterator(p), {}); };

// Save entries of 'list' in the vector of strings 'names'.
std::vector<std::string> names;
for(auto& entry : list())
{
  names.push_back(entry.path().string());
}

4 Mart 2017 Cumartesi

graph labed_graph Sınıfı

Giriş
Şu satırları dahil ederiz.
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/labeled_graph.hpp>
Açıklaması şöyle
This file implements a utility for creating mappings from arbitrary identifiers to the vertices of a graph.
Yani id -> vertex_descriptor arasında ilişki tutmak gerekiyorsa kullanılır.

Tanımlama
Örnek 1
Şöyle yaparız.
typedef boost::labeled_graph<
boost::adjacency_list<>,
std::string
> Graph;
Örnek 2
Şöyle yaparız.
typedef boost::adjacency_list<listS, vecS, undirectedS> AdjList;
typedef boost::labeled_graph<AdjList, size_t, mapS> Graph;
Constructor
Şöyle yaparız.
Graph g;
Doldurmak
Aynı id'ye sahip iki tane vertex eklenemez. Şöyle yaparız. Bunu denersek add_vertex bir öne eklenmiş olan nesnesi döndürür.
while (std::getline(infile, line)) {

  std::istringstream iss(line);

  size_t vid1, vid2;
  if (iss >> vid1 >> vid2) {
    auto v1 = add_vertex(vid1, g);
    auto v2 = add_vertex(vid2, g);

    add_edge(v1, v2, g);
  }

}




graph in_edges metodu

Giriş
out_edges() metodu ile kardeştir.

in_edges metodu
Bir düğüme doğru bağlantısı olan edge'leri verir. Elimizde bir graph, bir vertex olsun.
typedef adjacency_list<vecS, vecS, bidirectionalS> Graph;
Graph g; // Given graph

int v = ...; // Given vertex
Şöyle yaparız.
typename graph_traits < graph_t >::in_edge_iterator ei, ei_end;
tie(ei,ei_end) = in_edges(v,g);

2 Mart 2017 Perşembe

date_time gregorian date_facet Sınıfı

Giriş
stream'e yazdırma için kullanırız.

Constructor
Şöyle yaparız.
boost::gregorian::date_facet("%Y-%m-%d %H:%M:%S");
Şöyle yaparız.
auto dfacet = new boost::gregorian::date_facet("%m/%d/%Y");
Örnek 1
Şöyle yaparız.
const std::locale fmt(std::locale::classic(),
                      new boost::gregorian::date_facet("%m/%d/%Y"));
std::string dateAsMMDDYYYY( const boost::gregorian::date& date )
{
  std::ostringstream os;
  os.imbue(fmt);
  os << date;
  return os.str();
}

1 Mart 2017 Çarşamba

asio posix stream_descriptor sınıfı

Constructor
Şöyle yaparız
asio::io_service ios;
asio::posix::stream_descriptor stream_desc (ios);
Constructor - fd
Şöyle yaparız.
asio::posix::stream_descriptor out(ios, ::dup(STDOUT_FILENO));
assign metodu - fd
Açılan file descriptor şöyle atanır.
int raw_fd = inotify_init ();
stream_desc.assign (raw_fd);
assign metodu - fd + error_code
Uygulamamızı şöyle kullanırız.
cat somefile.txt | myprog
Şöyle yaparız.
boost::system::error_code error;
stream_desc.assign(dup(STDIN_FILENO), error);
if ( error ) {
  ...
}
async_read_some metodu
Verilen buffer içine eldeki veri doldurulur.
stream_desc.async_read_some (buf.prepare(buf.max_size()),
        boost::bind(&notify_handler, asio::placeholders::error,
                    asio::placeholders::bytes_transferred));
is_open metodu
Şöyle yaparız.
if (stream_desc.is_open() ) {...}

multiprecision mpf_float Sınıfı

Giriş
Şu satırı dahil ederiz.
#include <boost/multiprecision/gmp.hpp>
mpf_float_100 ile benzer.

Constructor - double
Şöyle yaparız.
mp::mpf_float f (2);
Şöyle yaparız.
double da = -1500.0;
mp::mpf_float_100 a (da);
convert_to metodu
Şöyle yaparız.
mp::mpf_float_100 res = ...;
std::string  = res.convert_to<std::string>();