##dynamic dispatch
[routing] (http://is.gd/LqQjGB)
template<class T> | |
class Atomic { | |
private: | |
mutable T t; | |
mutable std::mutex m; | |
public: | |
Atomic( T t_ ) : t( t_ ) { } | |
template<typename F> | |
auto operator()( F f ) const -> decltype(f(t)) |
#==================================================================================================# | |
# # | |
# Copyright 2012 MaidSafe.net limited # | |
# # | |
# This MaidSafe Software is licensed to you under (1) the MaidSafe.net Commercial License, # | |
# version 1.0 or later, or (2) The General Public License (GPL), version 3, depending on which # | |
# licence you accepted on initial access to the Software (the "Licences"). # | |
# # | |
# By contributing code to the MaidSafe Software, or to this project generally, you agree to be # | |
# bound by the terms of the MaidSafe Contributor Agreement, version 1.0, found in the root # |
// from Eric Niebler's talk from C++Now 2014 https://www.youtube.com/watch?v=zgOF4NrQllo | |
class RegularCxx11 { | |
RegularCxx11(); | |
RegularCxx11(RegularCxx11 const &); | |
RegularCxx11(RegularCxx11 &&) noexcept; | |
~RegularCxx11(); | |
RegularCxx11 & operator=(RegularCxx11 const &); | |
RegularCxx11 & operator=(RegularCxx11 &&) noexcept; | |
friend bool operator==(RegularCxx11 const &, RegularCxx11 const &); | |
friend bool operator!=(RegularCxx11 const &, RegularCxx11 const &); |
/* | |
A last recently used cache that has a capacity and time to live setting. Passing a void ValueType | |
allows this object to be used as a firewall / filter type device that can hold and check | |
for keys already seen. Users can set the capacity, time_to_live or both allowing a cache that will | |
not hold data too long or stay full if it not being accessed frequently. This should | |
allow the cache to not hold stale information at the cost of a check every time we add that looks | |
at the timestamp of the last entry in the list and compares this to the maps timestamp. | |
Research links | |
http://en.wikipedia.org/wiki/Cache_algorithms |
#include "maidsafe/common/test.h" | |
#include <iostream> | |
#include "asio/io_service.hpp" | |
#include "asio.hpp" | |
// Note: the handler signatures here must contain | |
// boost::system::error_code as first argument (not std::error_code) | |
// for asio to understand it is to indicate errors. | |
template <typename CompletionToken> |
#include <iostream> | |
#include <string> | |
using namespace std; | |
template <typename Child> | |
struct Routing { | |
Routing() = delete; | |
explicit Routing(std::string s) : t(s) {} | |
void Get() { static_cast<Child*>(this)->FacadeGet(); } |
/* Copyright 2014 MaidSafe.net limited | |
This MaidSafe Software is licensed to you under (1) the MaidSafe.net Commercial License, | |
version 1.0 or later, or (2) The General Public License (GPL), version 3, depending on which | |
licence you accepted on initial access to the Software (the "Licences"). | |
By contributing code to the MaidSafe Software, or to this project generally, you agree to be | |
bound by the terms of the MaidSafe Contributor Agreement, version 1.0, found in the root | |
directory of this project at LICENSE, COPYING and CONTRIBUTOR respectively and also | |
available at: http://www.maidsafe.net/licenses | |
Unless required by applicable law or agreed to in writing, the MaidSafe Software distributed | |
under the GPL Licence is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS |
##dynamic dispatch
[routing] (http://is.gd/LqQjGB)
use std::net::{IpAddr, SocketAddr, UdpSocket}; | |
fn main() { | |
let local_addr = SocketAddr::new(IpAddr::new_v4(0, 0, 0, 0), 3671 ); | |
let mut socket = match UdpSocket::bind(&local_addr) { | |
Ok(s) => s, | |
Err(e) => panic!("couldn't bind socket: {}", e), | |
}; | |
match socket.join_multicast(&IpAddr::new_v4(224, 0, 23, 12)) { | |
Err(why) => println!("! {}", why), |
union Endian { | |
char c; | |
int i; | |
Endian(void) : i(1) { }; | |
bool big(void) { return !!c; }; | |
} endian; | |
cerr << (endian.big() ? "big" : "little"); |