don't pull in namespace std

This commit is contained in:
Danny Robson 2016-03-11 13:28:56 +11:00
parent 90386f63fe
commit a59844be98
12 changed files with 97 additions and 100 deletions

View File

@ -31,10 +31,7 @@
#include <memory>
using namespace std;
//-----------------------------------------------------------------------------
///////////////////////////////////////////////////////////////////////////////
debug::backtrace::backtrace (void):
m_frames (DEFAULT_DEPTH) {
@ -49,7 +46,7 @@ debug::backtrace::backtrace (void):
}
//-----------------------------------------------------------------------------
///////////////////////////////////////////////////////////////////////////////
static std::string
addr2line (const void *addr)
{
@ -74,7 +71,7 @@ addr2line (const void *addr)
}
//-----------------------------------------------------------------------------
///////////////////////////////////////////////////////////////////////////////
ostream&
debug::operator <<(ostream &os, const debug::backtrace &rhs) {
const auto frames = rhs.frames ();

View File

@ -19,18 +19,18 @@
#include <iostream>
using namespace std;
///////////////////////////////////////////////////////////////////////////////
debug::backtrace::backtrace (void):
m_frames (DEFAULT_DEPTH)
{ ; }
ostream&
debug::operator <<(ostream &os, const debug::backtrace&) {
os << "null backtrace";
return os;
///////////////////////////////////////////////////////////////////////////////
std::ostream&
debug::operator <<(std::ostream &os, const debug::backtrace&)
{
return os << "null_backtrace";
}

View File

@ -19,44 +19,48 @@
#include <cmath>
using namespace std;
/* Constructors */
///////////////////////////////////////////////////////////////////////////////
template <unsigned int E, unsigned int S>
ieee_float<E, S>::ieee_float (void)
{ ; }
//-----------------------------------------------------------------------------
template <unsigned int E, unsigned int S>
ieee_float<E, S>::ieee_float (floating_t _floating):
m_floating (_floating)
{ ; }
//-----------------------------------------------------------------------------
template <unsigned int E, unsigned int S>
ieee_float<E, S>::ieee_float (const ieee_float &rhs):
m_bits (rhs.m_bits)
{ ; }
/* Classifiers */
///////////////////////////////////////////////////////////////////////////////
template <unsigned int E, unsigned int S>
bool
ieee_float<E, S>::is_zero (void) const {
ieee_float<E, S>::is_zero (void) const
{
return m_components.exponent == 0 &&
m_components.significand == 0;
}
//-----------------------------------------------------------------------------
template <unsigned int E, unsigned int S>
bool
ieee_float<E, S>::is_subnormal (void) const {
ieee_float<E, S>::is_subnormal (void) const
{
return m_components.exponent == 0 &&
m_components.significand != 0;
}
//-----------------------------------------------------------------------------
template <unsigned int E, unsigned int S>
bool
ieee_float<E, S>::is_inifinity (void) const {
@ -64,6 +68,7 @@ ieee_float<E, S>::is_inifinity (void) const {
m_components.significand == 0;
}
//-----------------------------------------------------------------------------
template <unsigned int E, unsigned int S>
bool
ieee_float<E, S>::is_nan (void) const {
@ -71,6 +76,8 @@ ieee_float<E, S>::is_nan (void) const {
m_components.significand != 0;
}
///////////////////////////////////////////////////////////////////////////////
template <unsigned int E, unsigned int S>
bool
ieee_float<E, S>::operator==(floating_t _floating) const {
@ -90,25 +97,7 @@ ieee_float<E, S>::operator==(floating_t _floating) const {
}
#include <iostream>
//template <unsigned int E, unsigned int S>
//bool
//ieee_float<E, S>::almost_equal (floating_t a,
// floating_t b) {
// // Static cast to avoid integer casting warnings when using uint16_t for half
// static const floating_t epsilon = static_cast<floating_t> (0.001);
// const floating_t diff = static_cast<floating_t> (std::fabs (a - b));
//
// // * Use an exact equality first so that infinities are not indirectly compared. This would generate NaNs in the diff.
// // * Do not use gte or lte. This stops an infinite from making infinities on both sides of the inequality.
// return exactly_equal (a, b) ||
// diff < epsilon * std::fabs (a) ||
// diff < epsilon * std::fabs (b);
//}
///////////////////////////////////////////////////////////////////////////////
template <unsigned int E, unsigned int S>
bool
ieee_float<E, S>::almost_equal (floating_t a,
@ -118,7 +107,8 @@ ieee_float<E, S>::almost_equal (floating_t a,
}
// Based on the cynus `AlmostEqual2sComplement`
//-----------------------------------------------------------------------------
// Based on the Cygnus `AlmostEqual2sComplement` function
template <unsigned int E, unsigned int S>
bool
ieee_float<E, S>::almost_equal (floating_t _a,
@ -164,7 +154,7 @@ ieee_float<E, S>::almost_equal (floating_t _a,
}
//-----------------------------------------------------------------------------
///////////////////////////////////////////////////////////////////////////////
template class ieee_float< 5, 10>; // ieee_half
template class ieee_float< 8, 23>; // ieee_single;
template class ieee_float<11, 52>; // ieee_double;

1
io.cpp
View File

@ -31,7 +31,6 @@
#include <stdexcept>
using namespace std;
using namespace util;

View File

@ -26,9 +26,6 @@
#include <iostream>
using namespace std;
///////////////////////////////////////////////////////////////////////////////
const ipv4::ip ipv4::ip::LOOPBACK (127, 0, 0, 1);
const ipv4::ip ipv4::ip::ANY ( 0, 0, 0, 0);
@ -142,6 +139,6 @@ ipv4::ip::ip (const std::string &data)
//-----------------------------------------------------------------------------
ipv4::ip
ipv4::ip::parse (const string &data)
ipv4::ip::parse (const std::string &data)
{ return ipv4::ip (data); }

View File

@ -29,12 +29,10 @@
#include <arpa/inet.h>
#endif
//-----------------------------------------------------------------------------
using namespace net;
using namespace std;
using net::address;
//-----------------------------------------------------------------------------
///////////////////////////////////////////////////////////////////////////////
#ifdef __WIN32
const char* inet_ntop(int af, const void* src, char* dst, int size){
struct sockaddr_in srcaddr;
@ -50,20 +48,22 @@ const char* inet_ntop(int af, const void* src, char* dst, int size){
#endif
//-----------------------------------------------------------------------------
template <domain D>
///////////////////////////////////////////////////////////////////////////////
template <net::domain D>
typename address<D>::port_type
address<D>::port (void) const
{ return m_port; }
template <domain D>
//-----------------------------------------------------------------------------
template <net::domain D>
void
address<D>::set_port (const port_type &_port)
{ m_port = _port; }
template <domain D>
//-----------------------------------------------------------------------------
template <net::domain D>
typename address<D>::ip_type
address<D>::resolve (const std::string &str) {
addrinfo hint;
@ -81,19 +81,19 @@ address<D>::resolve (const std::string &str) {
}
//-----------------------------------------------------------------------------
///////////////////////////////////////////////////////////////////////////////
namespace net {
template <>
address<domain::INET>::address (const sockaddr_type &addr):
address<net::domain::INET>::address (const sockaddr_type &addr):
m_ip (addr.sin_addr.s_addr),
m_mask (0),
m_port (ntoh (addr.sin_port))
{
CHECK (addr.sin_family == (int)domain::INET);
CHECK (addr.sin_family == (int)net::domain::INET);
}
template <domain D>
template <net::domain D>
address<D>::address (const std::string &_addr,
port_type _port):
m_ip (resolve (_addr)),
@ -103,11 +103,11 @@ namespace net {
template <>
address<domain::INET>::sockaddr_type
address<domain::INET>::to_sockaddr (void) const {
address<net::domain::INET>::sockaddr_type
address<net::domain::INET>::to_sockaddr (void) const {
sockaddr_type addr;
addr.sin_family = (int)domain::INET;
addr.sin_family = (int)net::domain::INET;
addr.sin_port = hton (m_port);
addr.sin_addr.s_addr = m_ip.m_integer;
@ -117,11 +117,11 @@ namespace net {
template <>
std::string
address<domain::INET>::to_string (void) const {
address<net::domain::INET>::to_string (void) const {
char dest[INET_ADDRSTRLEN + 1];
sockaddr_type addr = to_sockaddr ();
if (NULL == inet_ntop ((int)domain::INET, &addr.sin_addr, dest, sizeof (dest)))
if (NULL == inet_ntop ((int)net::domain::INET, &addr.sin_addr, dest, sizeof (dest)))
net::error::throw_code ();
return dest;
}
@ -129,7 +129,7 @@ namespace net {
template <>
bool
address<domain::INET>::operator ==(const address<domain::INET> &rhs) {
address<net::domain::INET>::operator ==(const address<net::domain::INET> &rhs) {
return m_ip == rhs.m_ip &&
m_mask == rhs.m_mask &&
m_port == rhs.m_port;
@ -137,7 +137,7 @@ namespace net {
}
//-----------------------------------------------------------------------------
///////////////////////////////////////////////////////////////////////////////
std::ostream&
net::operator<< (std::ostream &os, const address<net::domain::INET> &addr) {
os << addr.to_string () << ":" << addr.port ();
@ -145,23 +145,23 @@ net::operator<< (std::ostream &os, const address<net::domain::INET> &addr) {
}
//-----------------------------------------------------------------------------
template <> const address<domain::INET>
address<domain::INET>::LOOPBACK ("127.0.0.1", 0);
///////////////////////////////////////////////////////////////////////////////
template <> const address<net::domain::INET>
address<net::domain::INET>::LOOPBACK ("127.0.0.1", 0);
template <> const address<domain::INET>
address<domain::INET>::ANY ("0.0.0.0", 0);
template <> const address<net::domain::INET>
address<net::domain::INET>::ANY ("0.0.0.0", 0);
namespace net {
template class address<domain::INET>;
template class address<net::domain::INET>;
}
//-----------------------------------------------------------------------------
//template <> const address<domain::INET6>
//address<domain::INET6>::LOOPBACK ("::1", 0);
//template <> const address<net::domain::INET6>
//address<net::domain::INET6>::LOOPBACK ("::1", 0);
//
//template <> const address<domain::INET6>
//address<domain::INET6>::ANY ("::0", 0);
//template <> const address<net::domain::INET6>
//address<net::domain::INET6>::ANY ("::0", 0);
//
//template class address<domain::INET6>;
//template class address<net::domain::INET6>;

View File

@ -20,23 +20,22 @@
#include "../cast.hpp"
//-----------------------------------------------------------------------------
using namespace std;
using namespace net;
using net::error;
//-----------------------------------------------------------------------------
///////////////////////////////////////////////////////////////////////////////
net::error::error (const std::string &_what):
runtime_error (_what)
{ ; }
//-----------------------------------------------------------------------------
net::error::error (int _code):
runtime_error (strerror (_code))
{ CHECK (_code != 0); }
//-----------------------------------------------------------------------------
///////////////////////////////////////////////////////////////////////////////
std::string
net::error::code_to_string (int code) {
#ifdef __WIN32
@ -54,7 +53,7 @@ net::error::code_to_string (int code) {
}
//-----------------------------------------------------------------------------
///////////////////////////////////////////////////////////////////////////////
void
net::error::throw_code (int code) {
#ifdef __WIN32

View File

@ -5,15 +5,14 @@
#include <iostream>
#include <cstdlib>
using namespace std;
///////////////////////////////////////////////////////////////////////////////
int
main (int, char **) {
util::TAP::logger tap;
util::stream::null out;
out << debug::backtrace() << endl;
out << debug::backtrace() << std::endl;
tap.noop ();
return EXIT_SUCCESS;

View File

@ -8,10 +8,12 @@
#include <cstdlib>
#include <cstring>
using namespace std;
///////////////////////////////////////////////////////////////////////////////
static const char *ALPHABET = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
//-----------------------------------------------------------------------------
static const struct {
uint32_t adler;
uint16_t bsd;
@ -24,6 +26,7 @@ static const struct {
};
///////////////////////////////////////////////////////////////////////////////
int
main (int, char**) {
util::TAP::logger tap;

View File

@ -6,9 +6,8 @@
#include <limits>
using namespace std;
///////////////////////////////////////////////////////////////////////////////
void
test_double (util::TAP::logger &tap)
{
@ -19,17 +18,17 @@ test_double (util::TAP::logger &tap)
sized_test tests[] = {
{ 0x3ff0000000000000, 1.0 },
{ 0x3ff0000000000001, 1.0 + numeric_limits<double>::epsilon () },
{ 0x3ff0000000000002, 1.0 + numeric_limits<double>::epsilon () * 2},
{ 0x3ff0000000000001, 1.0 + std::numeric_limits<double>::epsilon () },
{ 0x3ff0000000000002, 1.0 + std::numeric_limits<double>::epsilon () * 2},
{ 0x4000000000000000, 2.0 },
{ 0xc000000000000000, -2.0 },
{ 0x0000000000000001, numeric_limits<double>::denorm_min () },
{ 0x0010000000000000, numeric_limits<double>::min () }, // min positive normal
{ 0x7fefffffffffffff, numeric_limits<double>::max () }, // max
{ 0x0000000000000001, std::numeric_limits<double>::denorm_min () },
{ 0x0010000000000000, std::numeric_limits<double>::min () }, // min positive normal
{ 0x7fefffffffffffff, std::numeric_limits<double>::max () }, // max
{ 0x0000000000000000, 0.0 },
{ 0x8000000000000000, -0.0 },
{ 0x7ff0000000000000, numeric_limits<double>::infinity() },
{ 0xfff0000000000000, -numeric_limits<double>::infinity() },
{ 0x7ff0000000000000, std::numeric_limits<double>::infinity() },
{ 0xfff0000000000000, -std::numeric_limits<double>::infinity() },
{ 0x3fd5555555555555, 1.0 / 3.0 }
};
@ -46,6 +45,7 @@ test_double (util::TAP::logger &tap)
}
///////////////////////////////////////////////////////////////////////////////
void
test_single (util::TAP::logger &tap)
{
@ -57,13 +57,13 @@ test_single (util::TAP::logger &tap)
sized_test tests[] = {
{ 0x3f800000, 1.0f },
{ 0xc0000000, -2.0f },
{ 0x7f7fffff, numeric_limits<float>::max () },
{ 0x7f7fffff, std::numeric_limits<float>::max () },
{ 0x00000000, 0.0f },
{ 0x80000000, -0.0f },
{ 0x7f800000, numeric_limits<float>::infinity () },
{ 0xff800000, -numeric_limits<float>::infinity () },
{ 0x7f800000, std::numeric_limits<float>::infinity () },
{ 0xff800000, -std::numeric_limits<float>::infinity () },
{ 0x3eaaaaab, 1.0f / 3.0f }
};
@ -81,6 +81,7 @@ test_single (util::TAP::logger &tap)
}
///////////////////////////////////////////////////////////////////////////////
int
main (int, char **) {
util::TAP::logger tap;

View File

@ -7,9 +7,8 @@
#include <cstdlib>
#include <ctime>
using namespace std;
///////////////////////////////////////////////////////////////////////////////
// TODO: Use a more robust test like Chi-Square
void
test_bool (util::TAP::logger &tap)
@ -29,6 +28,7 @@ test_bool (util::TAP::logger &tap)
}
///////////////////////////////////////////////////////////////////////////////
// TODO: Use a more robust test like Kolmogorov-Smirnov
void
test_float (util::TAP::logger &tap)
@ -55,6 +55,7 @@ test_float (util::TAP::logger &tap)
}
///////////////////////////////////////////////////////////////////////////////
int
main (int, char **) {
util::TAP::logger tap;

View File

@ -1,10 +1,21 @@
#include <cstdlib>
#include <iostream>
#include "coord/iostream.hpp"
#include "extent.hpp"
#include "region.hpp"
int
main (int argc, char **argv)
{
(void)argc;
(void)argv;
util::point2u a { 0, 0 };
util::point2u b { 1, 1 };
util::region2u v { a, b };
std::cerr << v << '\n';
return EXIT_SUCCESS;
}