Commit cf96f365 authored by Dominik Charousset's avatar Dominik Charousset

removed default-ctor of option & added cppa::none

parent 1fc2e3b2
......@@ -113,6 +113,7 @@ cppa/message_future.hpp
cppa/message_header.hpp
cppa/message_id.hpp
cppa/message_priority.hpp
cppa/none.hpp
cppa/object.hpp
cppa/on.hpp
cppa/opencl.hpp
......
......@@ -49,7 +49,7 @@ struct conv_arg_impl {
if (iss >> result && iss.eof()) {
return result;
}
return {};
return none;
}
};
......
......@@ -34,6 +34,8 @@
#include <stdexcept>
#include <type_traits>
#include "cppa/none.hpp"
#define CPPA_OPTIONAL_VARIANT_DATA_CONCAT(x, y) x ## y
#define CPPA_OPTIONAL_VARIANT_DATA_GETTER(pos) \
......@@ -46,8 +48,6 @@
return CPPA_OPTIONAL_VARIANT_DATA_CONCAT(v, pos) ; \
}
namespace cppa { struct none_t; }
namespace cppa { namespace detail {
template<typename T>
......
......@@ -60,7 +60,7 @@ struct tuple_cast_impl {
mapping_vector mv;
if (matches<T...>(tup, mv)) return {Result::from(std::move(tup.vals()),
mv)};
return {};
return none;
}
};
......@@ -68,7 +68,7 @@ template<class Result, typename... T>
struct tuple_cast_impl<wildcard_position::nil, Result, T...> {
static inline optional<Result> safe(any_tuple& tup) {
if (matches<T...>(tup)) return {Result::from(std::move(tup.vals()))};
return {};
return none;
}
};
......@@ -82,7 +82,7 @@ struct tuple_cast_impl<wildcard_position::leading, Result, T...> {
static inline optional<Result> safe(any_tuple& tup) {
size_t o = tup.size() - (sizeof...(T) - 1);
if (matches<T...>(tup)) return {Result::offset_subtuple(tup.vals(), o)};
return {};
return none;
}
};
......
......@@ -216,7 +216,7 @@ struct ge_get_front {
std::reference_wrapper<
const typename util::rm_const_and_ref<decltype(what.front())>::type> > {
if (what.empty() == false) return {what.front()};
return {};
return none;
}
template<class C>
inline auto operator()(const C& what,
......@@ -227,7 +227,7 @@ struct ge_get_front {
>::type* = 0) const
-> optional<decltype(what.front())> {
if (what.empty() == false) return {what.front()};
return {};
return none;
}
};
......
/******************************************************************************\
* ___ __ *
* /\_ \ __/\ \ *
* \//\ \ /\_\ \ \____ ___ _____ _____ __ *
* \ \ \ \/\ \ \ '__`\ /'___\/\ '__`\/\ '__`\ /'__`\ *
* \_\ \_\ \ \ \ \L\ \/\ \__/\ \ \L\ \ \ \L\ \/\ \L\.\_ *
* /\____\\ \_\ \_,__/\ \____\\ \ ,__/\ \ ,__/\ \__/.\_\ *
* \/____/ \/_/\/___/ \/____/ \ \ \/ \ \ \/ \/__/\/_/ *
* \ \_\ \ \_\ *
* \/_/ \/_/ *
* *
* Copyright (C) 2011-2013 *
* Dominik Charousset <dominik.charousset@haw-hamburg.de> *
* *
* This file is part of libcppa. *
* libcppa is free software: you can redistribute it and/or modify it under *
* the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation; either version 2.1 of the License, *
* or (at your option) any later version. *
* *
* libcppa is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with libcppa. If not, see <http://www.gnu.org/licenses/>. *
\******************************************************************************/
#ifndef CPPA_NONE_HPP
#define CPPA_NONE_HPP
namespace cppa {
struct none_t { inline explicit operator bool() const { return false; } };
static constexpr none_t none = none_t{};
} // namespace cppa
#endif // CPPA_NONE_HPP
......@@ -33,6 +33,8 @@
#include <new>
#include <utility>
#include "cppa/none.hpp"
#include "cppa/config.hpp"
namespace cppa {
......@@ -50,11 +52,16 @@ class optional {
*/
typedef T type;
/**
/* *
* @brief Default constructor.
* @post <tt>valid() == false</tt>
*/
optional() : m_valid(false) { }
//optional() : m_valid(false) { }
/**
* @post <tt>valid() == false</tt>
*/
optional(const none_t&) : m_valid(false) { }
/**
* @brief Creates an @p option from @p value.
......@@ -62,13 +69,6 @@ class optional {
*/
optional(T value) : m_valid(false) { cr(std::move(value)); }
template<typename T0, typename T1, typename... Ts>
optional(T0&& arg0, T1&& arg1, Ts&&... args) : m_valid(false) {
cr(T(std::forward<T0>(arg0),
std::forward<T1>(arg1),
std::forward<Ts>(args)...));
}
optional(const optional& other) : m_valid(false) {
if (other.m_valid) cr(other.m_value);
}
......
......@@ -34,6 +34,8 @@
#include <stdexcept>
#include <type_traits>
#include "cppa/none.hpp"
#include "cppa/util/type_list.hpp"
#include "cppa/util/void_type.hpp"
#include "cppa/util/type_traits.hpp"
......@@ -47,8 +49,6 @@
namespace cppa {
struct none_t { };
template<int Value>
constexpr std::integral_constant<int, Value> make_int_token() { return {}; }
......
......@@ -144,7 +144,7 @@ void client_repl(const string& host, uint16_t port) {
try { return {std::stoi(str)}; }
catch (std::exception&) {
aout << "\"" << str << "\" is not an integer" << endl;
return {};
return none;
}
};
......
......@@ -258,7 +258,7 @@ class broker::doorman : public broker::servant {
continue_reading_result continue_reading() override {
CPPA_LOG_TRACE("");
for (;;) {
optional<stream_ptr_pair> opt;
optional<stream_ptr_pair> opt{none};
try { opt = m_ptr->try_accept_connection(); }
catch (std::exception& e) {
CPPA_LOG_ERROR(to_verbose_string(e));
......
......@@ -53,7 +53,7 @@ default_peer_acceptor::default_peer_acceptor(default_protocol* parent,
continue_reading_result default_peer_acceptor::continue_reading() {
CPPA_LOG_TRACE("");
for (;;) {
optional<stream_ptr_pair> opt;
optional<stream_ptr_pair> opt{none};
try { opt = m_ptr->try_accept_connection(); }
catch (exception& e) {
CPPA_LOG_ERROR(to_verbose_string(e));
......
......@@ -171,7 +171,7 @@ optional<stream_ptr_pair> ipv4_acceptor::try_accept_connection() {
if (accept_impl(result, m_fd, m_is_nonblocking)) {
return result;
}
return {};
return none;
}
} } // namespace cppa::detail
......@@ -58,7 +58,7 @@ detail::opt1_rvalue_builder<true> on_opt1(char short_opt,
else if (equal(begin(prefix) + 1, end(prefix), begin(input))) {
return input.substr(prefix.size() - 1);
}
return {};
return none;
};
vector<string> opts;
opts.push_back(lhs_str);
......
......@@ -290,7 +290,7 @@ int main() {
if (endptr != nullptr && *endptr == '\0') {
return result;
}
return {};
return none;
};
match("42") (
on(toint) >> [&](int i) {
......@@ -432,7 +432,7 @@ int main() {
return vec.back();
}
}
return {};
return none;
};
const char* svec[] = {"-n", "foo", "--name=bar", "-p", "2"};
......
......@@ -72,7 +72,7 @@ optional<int> str2int(const std::string& str) {
if (endptr != nullptr && *endptr == '\0') {
return result;
}
return {};
return none;
}
#define CPPA_CHECK_INVOKED(FunName, Args) \
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment