fix bitset for constexpr disabled

This commit is contained in:
bolero-MURAKAMI 2012-06-21 01:40:38 +09:00
parent 1f041c0edc
commit 71b6e89f92
6 changed files with 1517 additions and 1464 deletions

File diff suppressed because it is too large Load diff

1388
sprout/bitset/bitset.hpp Normal file

File diff suppressed because it is too large Load diff

28
sprout/bitset/bitwise.hpp Normal file
View file

@ -0,0 +1,28 @@
#ifndef SPROUT_BITSET_BITWISE_HPP
#define SPROUT_BITSET_BITWISE_HPP
#include <cstddef>
#include <sprout/config.hpp>
#include <sprout/bitset/bitset.hpp>
namespace sprout {
// 20.5.4 bitset operators:
template<std::size_t N>
inline SPROUT_CONSTEXPR bitset<N>
operator&(sprout::bitset<N> const& lhs, sprout::bitset<N> const& rhs) SPROUT_NOEXCEPT {
return sprout::bitset<N>(lhs.do_and(rhs));
}
template<std::size_t N>
inline SPROUT_CONSTEXPR bitset<N>
operator|(sprout::bitset<N> const& lhs, sprout::bitset<N> const& rhs) SPROUT_NOEXCEPT {
return sprout::bitset<N>(lhs.do_or(rhs));
}
template<std::size_t N>
inline SPROUT_CONSTEXPR bitset<N>
operator^(sprout::bitset<N> const& lhs, sprout::bitset<N> const& rhs) SPROUT_NOEXCEPT {
return sprout::bitset<N>(lhs.do_xor(rhs));
}
} // namespace sprout
#endif // #ifndef SPROUT_BITSET_BITWISE_HPP

18
sprout/bitset/hash.hpp Normal file
View file

@ -0,0 +1,18 @@
#ifndef SPROUT_BITSET_HASH_HPP
#define SPROUT_BITSET_HASH_HPP
#include <cstddef>
#include <sprout/config.hpp>
#include <sprout/bitset/bitset.hpp>
namespace sprout {
// 20.5.3 hash support
template<std::size_t N>
inline SPROUT_CONSTEXPR std::size_t
hash_value(sprout::bitset<N> const& v) {
return v.to_hash();
}
} // namespace sprout
#endif // #ifndef SPROUT_BITSET_HASH_HPP

71
sprout/bitset/io.hpp Normal file
View file

@ -0,0 +1,71 @@
#ifndef SPROUT_BITSET_IO_HPP
#define SPROUT_BITSET_IO_HPP
#include <cstddef>
#include <string>
#include <iosfwd>
#include <sprout/config.hpp>
#include <sprout/bitset/bitset.hpp>
namespace sprout {
// 20.5.4 bitset operators:
template<typename Char, typename Traits, std::size_t N>
inline std::basic_istream<Char, Traits>&
operator>>(std::basic_istream<Char, Traits>& lhs, sprout::bitset<N>& rhs) {
typedef typename Traits::char_type char_type;
typedef std::basic_istream<Char, Traits> istream_type;
typedef typename istream_type::ios_base ios_base;
std::basic_string<Char, Traits> tmp;
tmp.reserve(N);
char_type const zero = lhs.widen('0');
char_type const one = lhs.widen('1');
typename ios_base::iostate state = ios_base::goodbit;
typename istream_type::sentry sentry(lhs);
if (sentry) {
try {
for (std::size_t i = N; i > 0; --i) {
static typename Traits::int_type eof = Traits::eof();
typename Traits::int_type c1 = lhs.rdbuf()->sbumpc();
if (Traits::eq_int_type(c1, eof)) {
state |= ios_base::eofbit;
break;
} else {
char_type const c2 = Traits::to_char_type(c1);
if (Traits::eq(c2, zero)) {
tmp.push_back(zero);
} else if (Traits::eq(c2, one)) {
tmp.push_back(one);
} else if (Traits::eq_int_type(lhs.rdbuf()->sputbackc(c2), eof)) {
state |= ios_base::failbit;
break;
}
}
}
} catch(...) {
lhs.setstate(ios_base::badbit);
}
}
if (tmp.empty() && N) {
state |= ios_base::failbit;
} else {
rhs.copy_from_string(tmp, static_cast<std::size_t>(0), N, zero, one);
if (state) {
lhs.setstate(state);
return lhs;
}
}
return lhs;
}
template<typename Char, typename Traits, std::size_t N>
inline std::basic_ostream<Char, Traits>&
operator<<(std::basic_ostream<Char, Traits>& lhs, sprout::bitset<N> const& rhs) {
std::basic_string<Char, Traits> tmp;
std::ctype<Char> const& ct = std::use_facet<std::ctype<Char> >(lhs.getloc());
rhs.copy_to_string(tmp, ct.widen('0'), ct.widen('1'));
return lhs << tmp;
}
} // namespace sprout
#endif // #ifndef SPROUT_BITSET_IO_HPP

View file

@ -0,0 +1,8 @@
#ifndef SPROUT_FUNCTIONAL_HASH_BITSET_HPP
#define SPROUT_FUNCTIONAL_HASH_BITSET_HPP
#include <sprout/config.hpp>
#include <sprout/functional/hash/hash.hpp>
#include <sprout/bitset/hash.hpp>
#endif // #ifndef SPROUT_FUNCTIONAL_HASH_BITSET_HPP