first commit

This commit is contained in:
Jose Caban
2025-06-07 11:34:38 -04:00
commit 0eb2d7c07d
4708 changed files with 1500614 additions and 0 deletions

52
extern/ustl/1.5/bvt/Module.mk vendored Normal file
View File

@@ -0,0 +1,52 @@
################ Source files ##########################################
bvt/SRCS := $(wildcard bvt/bvt*.cc)
bvt/BVTS := $(bvt/SRCS:.cc=)
bvt/OBJS := $(addprefix $O,$(bvt/SRCS:.cc=.o))
bvt/LIBS := -L$(abspath $O.) -l${NAME}
ifdef BUILD_SHARED
bvt/LIBS := -Wl,--rpath=$(abspath $O.) ${bvt/LIBS}
endif
ifdef NOLIBSTDCPP
bvt/LIBS += ${STAL_LIBS} -lm
endif
CXXFLAGS += -I.
################ Compilation ###########################################
.PHONY: bvt/all bvt/run bvt/clean bvt/check
bvt/all: ${bvt/BVTS}
# The correct output of a bvt is stored in bvtXX.std
# When the bvt runs, its output is compared to .std
#
bvt/run: ${bvt/BVTS}
@echo "Running build verification tests:"
@for i in ${bvt/BVTS}; do \
echo "Running $$i"; \
./$$i < $$i.cc &> $$i.out; \
diff $$i.std $$i.out && rm -f $$i.out; \
done
${bvt/BVTS}: bvt/%: $Obvt/%.o $Obvt/stdtest.o ${ALLTGTS}
@echo "Linking $@ ..."
@${LD} ${LDFLAGS} -o $@ $< $Obvt/stdtest.o ${bvt/LIBS}
bvt/bench: $Obvt/bench.o $Obvt/stdtest.o ${ALLTGTS}
@echo "Linking $@ ..."
@${LD} ${LDFLAGS} -o $@ $< $Obvt/stdtest.o ${bvt/LIBS}
################ Maintenance ###########################################
clean: bvt/clean
bvt/clean:
@rm -f ${bvt/BVTS} ${bvt/OBJS} $(bvt/OBJS:.o=.d) bvt/bench $Obvt/bench.o $Obvt/stdtest.o $Obvt/bench.d $Obvt/stdtest.d
@rmdir $O/bvt &> /dev/null || true
check: bvt/run
bvt/check: check
${bvt/OBJS} $Obvt/stdtest.o $Obvt/bench.o: Makefile bvt/Module.mk Config.mk ${NAME}/config.h
-include ${bvt/OBJS:.o=.d} $Obvt/stdtest.d

311
extern/ustl/1.5/bvt/bench.cc vendored Normal file
View File

@@ -0,0 +1,311 @@
// This file is part of the uSTL library, an STL implementation.
//
// Copyright (c) 2005 by Mike Sharov <msharov@users.sourceforge.net>
// This file is free software, distributed under the MIT License.
#include <ustl.h>
#include <time.h>
using namespace ustl;
//----------------------------------------------------------------------
// Copy functions
//----------------------------------------------------------------------
#if __i386__ || __x86_64__
extern "C" void movsb_copy (const char* src, size_t nBytes, char* dest)
{
asm volatile ("rep\tmovsb":"+S"(src),"+D"(dest):"c"(nBytes):"memory");
}
extern "C" void movsd_copy (const char* src, size_t nBytes, char* dest)
{
asm volatile ("rep\tmovsl":"+S"(src),"+D"(dest):"c"(nBytes/4):"memory");
}
#if __x86_64__
extern "C" void movsq_copy (const char* src, size_t nBytes, char* dest)
{
asm volatile ("rep\tmovsq":"+S"(src),"+D"(dest):"c"(nBytes/8):"memory");
}
#endif
extern "C" void risc_copy (const char* src, size_t nBytes, char* dest)
{
unsigned long* ldest ((unsigned long*) dest);
const unsigned long* lsrc ((const unsigned long*) src);
nBytes /= sizeof(*lsrc);
do {
*ldest++ = *lsrc++;
} while (--nBytes);
}
extern "C" void unroll_copy (const char* src, size_t nBytes, char* dest)
{
unsigned long* ldest ((unsigned long*) dest);
const unsigned long* lsrc ((const unsigned long*) src);
nBytes /= 4 * sizeof(unsigned long);
do {
ldest[0] = lsrc[0];
ldest[1] = lsrc[1];
ldest[2] = lsrc[2];
ldest[3] = lsrc[3];
ldest += 4;
lsrc += 4;
} while (--nBytes);
}
#if CPU_HAS_MMX
extern "C" void mmx_copy (const char* src, size_t nBytes, char* dest)
{
nBytes /= 32;
do {
prefetch (src + 512, 0, 0);
asm (
"movq\t%4, %%mm0\n\t"
"movq\t%5, %%mm1\n\t"
"movq\t%6, %%mm2\n\t"
"movq\t%7, %%mm3\n\t"
"movq\t%%mm0, %0\n\t"
"movq\t%%mm1, %1\n\t"
"movq\t%%mm2, %2\n\t"
"movq\t%%mm3, %3"
: "=m"(dest[0]), "=m"(dest[8]), "=m"(dest[16]), "=m"(dest[24])
: "m"(src[0]), "m"(src[8]), "m"(src[16]), "m"(src[24])
: "mm0", "mm1", "mm2", "mm3", "st", "st(1)", "st(2)", "st(3)");
src += 32;
dest += 32;
} while (--nBytes);
simd::reset_mmx();
}
#endif // CPU_HAS_MMX
#if CPU_HAS_SSE
extern "C" void sse_copy (const char* src, size_t nBytes, char* dest)
{
nBytes /= 32;
do {
prefetch (src + 512, 0, 0);
asm (
"movaps\t%2, %%xmm0\n\t"
"movaps\t%3, %%xmm1\n\t"
"movntps\t%%xmm0, %0\n\t"
"movntps\t%%xmm1, %1"
: "=m"(dest[0]), "=m"(dest[16])
: "m"(src[0]), "m"(src[16])
: "xmm0", "xmm1");
src += 32;
dest += 32;
} while (--nBytes);
}
#endif // CPU_HAS_SSE
#endif // __i386__
extern "C" void memcpy_copy (const char* src, size_t nBytes, char* dest)
{
memcpy (dest, src, nBytes);
}
template <typename CopyFunction>
void TestCopyFunction (const char* name, CopyFunction pfn)
{
const uoff_t misalignment = 0;
const uoff_t headBytes = 0;
const uoff_t tailBytes = 0;
const size_t nIter = 128;
const size_t nBytes = 1024 * 1024 + misalignment;
string buf1 (nBytes), buf2 (nBytes);
iota (buf1.begin(), buf1.end(), '\x1');
fill (buf2, 0);
const clock_t first = clock();
for (uoff_t i = 0; i < nIter; ++ i)
(*pfn)(buf1.cdata() + headBytes, nBytes - headBytes - tailBytes, buf2.data() + headBytes + misalignment);
clock_t last = clock();
last += (last == first);
const size_t mbps = nIter * CLOCKS_PER_SEC / (last - first);
cout.format ("%s transfer rate is %4zu Mbps, data is ", name, mbps);
size_t nBad = 0;
for (uoff_t i = headBytes; i < buf1.size() - tailBytes; ++ i)
nBad += (buf1[i] != buf2[i + misalignment]);
if (!nBad)
cout << "GOOD\n";
else {
cout << "BAD\n";
for (uoff_t i = headBytes; i < buf1.size() - tailBytes; ++ i)
if (buf1[i] != buf2[i + misalignment])
cout.format ("\t\t%zu\tbuf1: %#x, buf2: %#x\n", i, (int) buf1[i], (int) buf2[i + misalignment]);
}
cout.flush();
}
//----------------------------------------------------------------------
// Fill functions
//----------------------------------------------------------------------
extern "C" void memset_fill (char* dest, size_t nBytes, char v)
{
memset (dest, v, nBytes);
}
#if __i386__ || __x86_64__
extern "C" void stosb_fill (char* dest, size_t nBytes, char v)
{
asm volatile (
"rep\tstosb\n\t"
: "=&D"(dest)
: "0"(dest), "a"(v), "c"(nBytes)
: "memory");
}
extern "C" void stosd_fill (char* dest, size_t nBytes, char v)
{
uint32_t lv;
pack_type (v, lv);
asm volatile (
"rep\tstosl\n\t"
: "=&D"(dest)
: "0"(dest), "a"(lv), "c"(nBytes / sizeof(lv))
: "memory");
}
extern "C" void risc_fill (char* dest, size_t nBytes, char v)
{
unsigned long lv;
pack_type (v, lv);
unsigned long* ldest ((unsigned long*) dest);
nBytes /= sizeof(lv);
do {
*ldest++ = lv;
} while (--nBytes);
}
extern "C" void unroll_fill (char* dest, size_t nBytes, char v)
{
unsigned long lv;
pack_type (v, lv);
unsigned long* ldest ((unsigned long*) dest);
nBytes /= 4 * sizeof(lv);
do {
ldest[0] = lv;
ldest[1] = lv;
ldest[2] = lv;
ldest[3] = lv;
ldest += 4;
} while (--nBytes);
}
#if CPU_HAS_MMX
extern "C" void mmx_fill (char* dest, size_t nBytes, char v)
{
asm volatile (
"movd %0, %%mm0 \n\t"
"punpcklbw %%mm0, %%mm0 \n\t"
"punpcklwd %%mm0, %%mm0 \n\t"
"punpckldq %%mm0, %%mm0"
::"r"(uint32_t(v))
: "mm0", "st");
const size_t nBlocks (nBytes / 32);
for (uoff_t i = 0; i < nBlocks; ++ i) {
prefetch (dest + 512, 1, 0);
asm volatile (
"movq %%mm0, %0 \n\t"
"movq %%mm0, %1 \n\t"
"movq %%mm0, %2 \n\t"
"movq %%mm0, %3"
: "=m"(dest[0]), "=m"(dest[8]), "=m"(dest[16]), "=m"(dest[24]));
dest += 32;
}
simd::reset_mmx();
}
#endif // CPU_HAS_MMX
#if CPU_HAS_SSE
extern "C" void sse_fill (char* dest, size_t nBytes, char v)
{
prefetch (dest + 512, 1, 0);
uint32_t v4 = uint32_t(v) * 0x01010101;
asm volatile (
"movd\t%0, %%xmm0\n\t"
"unpcklps\t%%xmm0, %%xmm0\n\t"
"movlhps\t%%xmm0, %%xmm0"
::"r"(v4) : "xmm0");
long i = nBytes / 32;
do {
asm volatile (
"movntps\t%%xmm0, (%0)\n\t"
"movntps\t%%xmm0, 16(%0)"
::"r"(dest):"memory");
dest += 32;
} while (--i);
asm("sfence");
}
#endif // CPU_HAS_MMX
#endif // __i386__
template <typename FillFunction>
void TestFillFunction (const char* name, FillFunction pfn)
{
const size_t nIter = 256;
const size_t nBytes = 1024 * 1024;
string buf1 (nBytes), buf2 (nBytes);
iota (buf1.begin(), buf1.end(), '\x1');
fill (buf2, 42);
clock_t first = clock();
for (uoff_t i = 0; i < nIter; ++ i)
(*pfn)(buf1.data(), nBytes, char(42));
clock_t last = clock();
last += (last == first);
const size_t mbps = nIter * CLOCKS_PER_SEC / (last - first);
cout << name << " transfer rate is " << mbps << " Mbps, data is ";
if (buf1 == buf2)
cout << "GOOD" << endl;
else
cout << "BAD" << endl;
cout.flush();
}
//----------------------------------------------------------------------
int main (void)
{
cout << "Testing fill" << endl;
cout << "---------------------------------------------------------" << endl;
#if __i386__ || __x86_64__
#if CPU_HAS_SSE
TestFillFunction ("sse_fill\t", &sse_fill);
#endif
#if CPU_HAS_MMX && HAVE_INT64_T
TestFillFunction ("mmx_fill\t", &mmx_fill);
#endif
TestFillFunction ("stosb_fill\t", &stosb_fill);
TestFillFunction ("stosd_fill\t", &stosd_fill);
TestFillFunction ("unroll_fill\t", &unroll_fill);
TestFillFunction ("risc_fill\t", &risc_fill);
#endif
TestFillFunction ("memset_fill\t", &memset_fill);
TestFillFunction ("fill_n\t\t", &fill_n<char*, char>);
cout << endl;
cout << "Testing copy" << endl;
cout << "---------------------------------------------------------" << endl;
#if __i386__ || __x86_64__
#if CPU_HAS_SSE
TestCopyFunction ("sse_copy\t", &sse_copy);
#endif
#if CPU_HAS_MMX
TestCopyFunction ("mmx_copy\t", &mmx_copy);
#endif
TestCopyFunction ("movsb_copy\t", &movsb_copy);
TestCopyFunction ("movsd_copy\t", &movsd_copy);
#if __x86_64__
TestCopyFunction ("movsq_copy\t", &movsq_copy);
#endif
TestCopyFunction ("risc_copy\t", &risc_copy);
TestCopyFunction ("unroll_copy\t", &unroll_copy);
#endif
TestCopyFunction ("memcpy_copy\t", &memcpy_copy);
TestCopyFunction ("copy_n\t\t", &copy_n<const char*, char*>);
return (EXIT_SUCCESS);
}

46
extern/ustl/1.5/bvt/bvt00.cc vendored Normal file
View File

@@ -0,0 +1,46 @@
// This file is part of the uSTL library, an STL implementation.
//
// Copyright (c) 2005 by Mike Sharov <msharov@users.sourceforge.net>
// This file is free software, distributed under the MIT License.
#include "stdtest.h"
void WriteCML (const cmemlink& l)
{
cout.format ("cmemlink{%zu}: ", l.size());
const void* pv = l.cdata();
const char* pc = reinterpret_cast<const char*>(pv);
size_t nc = l.size();
if (pc[nc - 1] == 0)
-- nc;
cout.write (l.begin(), nc);
cout << endl;
}
void TestCML (void)
{
const char hello[] = "Hello world!";
const char* phello = hello; // const storage is sometimes copied on pointing
cmemlink a, b;
a.link (phello, VectorSize(hello));
if (a.begin() != phello)
cout.format ("a.begin() failed: %p != %p\n", a.begin(), phello);
a.link (VectorRange (hello));
if (*(const char*)(a.begin() + 5) != hello[5])
cout.format ("begin()[5] failed: %c != %c\n", *(const char*)(a.begin() + 5), VectorElement(hello,5));
if (a.size() != VectorSize(hello))
cout << "link to VectorRange doesn't work\n";
if (0 != memcmp (a.begin(), hello, VectorSize(hello)))
cout << "memcmp failed on cmemlink\n";
b.static_link (hello);
WriteCML (a);
WriteCML (b);
if (!(a == b))
cout << "operator== failed on cmemlink\n";
b.resize (VectorSize(hello) - 5);
a = b;
WriteCML (a);
}
StdBvtMain (TestCML)

3
extern/ustl/1.5/bvt/bvt00.std vendored Normal file
View File

@@ -0,0 +1,3 @@
cmemlink{13}: Hello world!
cmemlink{13}: Hello world!
cmemlink{8}: Hello wo

60
extern/ustl/1.5/bvt/bvt01.cc vendored Normal file
View File

@@ -0,0 +1,60 @@
// This file is part of the uSTL library, an STL implementation.
//
// Copyright (c) 2005 by Mike Sharov <msharov@users.sourceforge.net>
// This file is free software, distributed under the MIT License.
#include "stdtest.h"
void WriteCML (const cmemlink& l)
{
cout.format ("memlink{%zu}: ", l.size());
const char* pc = reinterpret_cast<const char*>(l.cdata());
size_t nc = l.size();
if (pc[nc - 1] == 0)
-- nc;
cout.write (l.cdata(), nc);
cout << endl;
}
void TestML (void)
{
char str[] = "abcdefghijklmnopqrstuvwzyz";
memlink::const_pointer cstr = str;
memlink a, b;
a.static_link (str);
if (a.begin() != str)
cout << "begin() failed on memlink\n";
a.link (VectorRange(str));
if (a.begin() + 5 != &str[5])
cout << "begin() + 5 failed on memlink\n";
if (0 != memcmp (a.begin(), str, VectorSize(str)))
cout << "memcmp failed on memlink\n";
WriteCML (a);
b.link (cstr, VectorSize(str));
if (b.data() != cstr)
cout << "begin() of const failed on cmemlink\n";
if (b.cmemlink::begin() != cstr)
cout << "begin() failed on cmemlink\n";
WriteCML (b);
if (!(a == b))
cout << "operator== failed on cmemlink\n";
b.resize (VectorSize(str) - 2);
a = b;
if (a.data() != b.data())
cout << "begin() after assignment failed on cmemlink\n";
a.relink (str, VectorSize(str) - 1);
WriteCML (a);
a.insert (a.begin() + 5, 9);
a.fill (a.begin() + 5, "-", 1, 9);
WriteCML (a);
a.erase (a.begin() + 9, 7);
a.fill (a.end() - 7, "=", 1, 7);
WriteCML (a);
a.fill (a.begin() + 5, "TEST", 4, 3);
WriteCML (a);
copy_n (cstr, VectorSize(str) - 1, a.begin());
WriteCML (a);
}
StdBvtMain (TestML)

7
extern/ustl/1.5/bvt/bvt01.std vendored Normal file
View File

@@ -0,0 +1,7 @@
memlink{27}: abcdefghijklmnopqrstuvwzyz
memlink{27}: abcdefghijklmnopqrstuvwzyz
memlink{26}: abcdefghijklmnopqrstuvwzyz
memlink{26}: abcde---------fghijklmnopq
memlink{26}: abcde----hijklmnopq=======
memlink{26}: abcdeTESTTESTTESTpq=======
memlink{26}: abcdeTESTTESTTESTpq=======

72
extern/ustl/1.5/bvt/bvt02.cc vendored Normal file
View File

@@ -0,0 +1,72 @@
// This file is part of the uSTL library, an STL implementation.
//
// Copyright (c) 2005 by Mike Sharov <msharov@users.sourceforge.net>
// This file is free software, distributed under the MIT License.
#include "stdtest.h"
void WriteCML (const memblock& l)
{
cout.format ("memblock{%zu}: ", l.size());
const char* pc = reinterpret_cast<const char*>(l.cdata());
size_t nc = l.size();
while (nc && pc[nc - 1] == 0)
-- nc;
cout.write (l.cdata(), nc);
cout << endl;
}
void TestMB (void)
{
char strTest[] = "abcdefghijklmnopqrstuvwxyz";
const size_t strTestLen = strlen(strTest);
const char* cstrTest = strTest;
memblock a, b;
a.link (strTest, strTestLen);
if (a.begin() != strTest)
cout << "begin() failed on memblock\n";
if (a.begin() + 5 != &strTest[5])
cout << "begin() + 5 failed on memblock\n";
if (0 != memcmp (a.begin(), strTest, strTestLen))
cout << "memcmp failed on memblock\n";
WriteCML (a);
b.link (cstrTest, strTestLen);
if (b.data() != cstrTest)
cout << "begin() of const failed on memblock\n";
if (b.cmemlink::begin() != cstrTest)
cout << "cmemlink::begin() failed on memblock\n";
WriteCML (b);
if (!(a == b))
cout << "operator== failed on memblock\n";
b.copy_link();
if (b.data() == NULL || b.cdata() == cstrTest)
cout << "copy_link failed on memblock\n";
if (!(a == b))
cout << "copy_link didn't copy\n";
b.resize (strTestLen - 2);
a = b;
if (a.begin() == b.begin())
cout << "Assignment does not copy a link\n";
a.deallocate();
a.assign (strTest, strTestLen);
WriteCML (a);
a.insert (a.begin() + 5, 9);
a.fill (a.begin() + 5, "-", 1, 9);
WriteCML (a);
a.erase (a.begin() + 2, 7);
a.fill (a.end() - 7, "=", 1, 7);
WriteCML (a);
a.fill (a.begin() + 5, "TEST", 4, 3);
WriteCML (a);
a.resize (26 + 24);
a.fill (a.begin() + 26, "-+=", 3, 24 / 3);
WriteCML (a);
a.resize (0);
WriteCML (a);
a.resize (strTestLen + strTestLen / 2);
WriteCML (a);
}
StdBvtMain (TestMB)

9
extern/ustl/1.5/bvt/bvt02.std vendored Normal file
View File

@@ -0,0 +1,9 @@
memblock{26}: abcdefghijklmnopqrstuvwxyz
memblock{26}: abcdefghijklmnopqrstuvwxyz
memblock{26}: abcdefghijklmnopqrstuvwxyz
memblock{35}: abcde---------fghijklmnopqrstuvwxyz
memblock{28}: ab-----fghijklmnopqrs=======
memblock{28}: ab---TESTTESTTESTpqrs=======
memblock{50}: ab---TESTTESTTESTpqrs=====-+=-+=-+=-+=-+=-+=-+=-+=
memblock{0}:
memblock{39}: ab---TESTTESTTESTpqrs=====-+=-+=-+=-+=-

117
extern/ustl/1.5/bvt/bvt03.cc vendored Normal file
View File

@@ -0,0 +1,117 @@
// This file is part of the uSTL library, an STL implementation.
//
// Copyright (c) 2005 by Mike Sharov <msharov@users.sourceforge.net>
// This file is free software, distributed under the MIT License.
#include "stdtest.h"
#include <unistd.h>
void TestStreams (void)
{
const uint8_t magic_Char = 0x12;
const uint16_t magic_Short = 0x1234;
const uint32_t magic_Int = 0x12345678;
const float magic_Float = 0.12345678;
const double magic_Double = 0.123456789123456789;
const bool magic_Bool = true;
char c = magic_Char;
unsigned char uc = magic_Char;
int i = magic_Int;
short si = magic_Short;
long li = magic_Int;
unsigned int ui = magic_Int;
unsigned short usi = magic_Short;
unsigned long uli = magic_Int;
float f = magic_Float;
double d = magic_Double;
bool bv = magic_Bool;
size_t totalSize = stream_size_of(c);
totalSize += stream_size_of(uc);
totalSize = Align (totalSize, alignof(bv));
totalSize += stream_size_of(bv);
totalSize = Align (totalSize, alignof(i));
totalSize += stream_size_of(i);
totalSize += stream_size_of(ui);
totalSize = Align (totalSize);
totalSize += stream_size_of(li);
totalSize += stream_size_of(uli);
totalSize = Align (totalSize, alignof(f));
totalSize += stream_size_of(f);
totalSize = Align (totalSize, alignof(d));
totalSize += stream_size_of(d);
totalSize += stream_size_of(si);
totalSize += stream_size_of(usi);
memblock b;
b.resize (totalSize);
b.fill (b.begin(), "\xCD", 1, b.size());
ostream os (b);
os << c;
os << uc;
os << ios::talign<bool>() << bv;
os << ios::talign<int>() << i;
os << ui;
os << ios::align() << li;
os << uli;
os << ios::talign<float>() << f;
os << ios::talign<double>() << d;
os << si;
os << usi;
if (b.size() == os.pos())
cout << "Correct number of bytes written\n";
else
cout.format ("Incorrect (%zu of %zu) number of bytes written\n", os.pos(), b.size());
cout.flush();
c = 0;
uc = 0;
bv = false;
i = ui = li = uli = 0;
f = 0; d = 0;
si = usi = 0;
istream is (b);
is >> c;
is >> uc;
is >> ios::talign<bool>() >> bv;
is >> ios::talign<int>() >> i;
is >> ui;
is >> ios::align() >> li;
is >> uli;
is >> ios::talign<float>() >> f;
is >> ios::talign<double>() >> d;
is >> si;
is >> usi;
if (is.pos() != b.size())
cout << "Positional error\n";
cout.format ("Values:\n"
"char: 0x%02X\n"
"u_char: 0x%02X\n"
"bool: %d\n"
"int: 0x%08X\n"
"u_int: 0x%08X\n"
"long: 0x%08lX\n"
"u_long: 0x%08lX\n"
"float: %.8f\n"
"double: %.16f\n"
"short: 0x%04X\n"
"u_short: 0x%04X\n",
static_cast<int>(c), static_cast<int>(uc), static_cast<int>(bv),
i, ui, li, uli, f, d, static_cast<int>(si), static_cast<int>(usi));
if (isatty (STDIN_FILENO)) {
cout << "\nBinary dump:\n";
foreach (memblock::const_iterator, pc, b) {
if (pc > b.begin() && !(distance(b.begin(), pc) % 8))
cout << endl;
cout.format ("%02X ", uint8_t(*pc));
}
cout << endl;
}
}
StdBvtMain (TestStreams)

13
extern/ustl/1.5/bvt/bvt03.std vendored Normal file
View File

@@ -0,0 +1,13 @@
Correct number of bytes written
Values:
char: 0x12
u_char: 0x12
bool: 1
int: 0x12345678
u_int: 0x12345678
long: 0x12345678
u_long: 0x12345678
float: 0.12345678
double: 0.1234567891234568
short: 0x1234
u_short: 0x1234

68
extern/ustl/1.5/bvt/bvt04.cc vendored Normal file
View File

@@ -0,0 +1,68 @@
// This file is part of the uSTL library, an STL implementation.
//
// Copyright (c) 2005 by Mike Sharov <msharov@users.sourceforge.net>
// This file is free software, distributed under the MIT License.
#include "stdtest.h"
class A {
public:
A (void)
{ cout << "A::A\n"; }
A (const A&)
{ cout << "Copy A::A\n"; }
const A& operator= (const A&)
{ cout << "A::operator=\n"; return (*this); }
~A (void)
{ cout << "A::~A\n"; }
};
void TestVector (void)
{
static const int c_TestNumbers[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 13, 14, 15, 16, 17, 18 };
vector<int> v;
v.push_back (1);
cout << v << endl;
v.reserve (20);
cout.format ("Reserved to capacity() == %zu (%zu used, ", v.capacity(), v.size());
if (v.max_size() == SIZE_MAX / sizeof(int))
cout << "SIZE_MAX/elsize";
else
cout << v.max_size();
cout << " max)\n";
v.insert (v.begin() + 1, 1 + VectorRange(c_TestNumbers));
cout << v << endl;
cout.format ("front() = %d, back() = %d\n", v.front(), v.back());
v.erase (v.begin());
v.pop_back();
cout << v << endl;
v.insert (v.begin() + 10, 3, 666);
v.at(5) = 777;
cout << v << endl;
v.resize (v.size() - 5);
if (v.empty())
cout << "v is now empty\n";
cout << v << endl;
cout.format ("v[5] == %d\n", v[5]);
v.clear();
if (v.empty())
cout << "v is now empty\n";
vector<int> v2 (20, 66);
cout << v2 << endl;
v2.assign (20, 33);
cout << v2 << endl;
v.assign (VectorRange (c_TestNumbers));
cout << v << endl;
if (v == v2)
cout << "v == v2\n";
v2 = v;
if (v == v2)
cout << "v == v2\n";
vector<A> ctv;
A a;
ctv.assign (3, a);
ctv.pop_back();
cout << "Class insertion testing successful\n";
}
StdBvtMain (TestVector)

25
extern/ustl/1.5/bvt/bvt04.std vendored Normal file
View File

@@ -0,0 +1,25 @@
(1)
Reserved to capacity() == 20 (1 used, SIZE_MAX/elsize max)
(1,2,3,4,5,6,7,8,9,10,11,12,13,13,14,15,16,17,18)
front() = 1, back() = 18
(2,3,4,5,6,7,8,9,10,11,12,13,13,14,15,16,17)
(2,3,4,5,6,777,8,9,10,11,666,666,666,12,13,13,14,15,16,17)
(2,3,4,5,6,777,8,9,10,11,666,666,666,12,13)
v[5] == 777
v is now empty
(66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66)
(33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33,33)
(1,2,3,4,5,6,7,8,9,10,11,12,13,13,14,15,16,17,18)
v == v2
A::A
A::A
A::A
A::A
A::operator=
A::operator=
A::operator=
Class insertion testing successful
A::~A
A::~A
A::~A
A::~A

399
extern/ustl/1.5/bvt/bvt05.cc vendored Normal file
View File

@@ -0,0 +1,399 @@
// This file is part of the uSTL library, an STL implementation.
//
// Copyright (c) 2005 by Mike Sharov <msharov@users.sourceforge.net>
// This file is free software, distributed under the MIT License.
#include "stdtest.h"
typedef vector<int> intvec_t;
typedef const intvec_t& rcintvec_t;
typedef intvec_t::const_iterator intiter_t;
static void printint (int i)
{
cout.format ("%d ", i);
}
static void PrintVector (rcintvec_t v)
{
cout << "{ ";
foreach (intiter_t, i, v)
printint (*i);
cout << "}\n";
}
static bool is_even (int i)
{
return (i % 2 == 0);
}
static int sqr (int i)
{
return (i * i);
}
static int genint (void)
{
static int counter = 0;
return (counter++);
}
// In its own function because compilers differ in selecting const/nonconst
// members where no choice is needed.
//
static void TestEqualRange (rcintvec_t v)
{
pair<intiter_t,intiter_t> rv;
rv = equal_range (v, 10);
cout.format ("Range of 10 is { %2zd, %2zd }\n", abs_distance (v.begin(), rv.first), abs_distance (v.begin(), rv.second));
rv = equal_range (v, 0);
cout.format ("Range of 0 is { %2zd, %2zd }\n", abs_distance (v.begin(), rv.first), abs_distance (v.begin(), rv.second));
rv = equal_range (v, 100);
cout.format ("Range of 100 is { %2zd, %2zd }\n", abs_distance (v.begin(), rv.first), abs_distance (v.begin(), rv.second));
}
template <typename T>
void TestBigFill (const size_t size, const T magic)
{
vector<T> vbig (size);
fill (vbig.begin() + 1, vbig.end(), magic); // offset to test prealignment loop
typename vector<T>::const_iterator iMismatch;
iMismatch = find_if (vbig.begin() + 1, vbig.end(), bind1st (not_equal_to<T>(), magic));
if (iMismatch == vbig.end())
cout << "works\n";
else
cout.format ("does not work: mismatch at %zd, =0x%lX\n", abs_distance (vbig.begin(), iMismatch), (unsigned long)(*iMismatch));
}
template <typename T>
void TestBigCopy (const size_t size, const T magic)
{
vector<T> vbig1 (size), vbig2 (size);
fill (vbig1, magic);
copy (vbig1.begin() + 1, vbig1.end(), vbig2.begin() + 1); // offset to test prealignment loop
typedef typename vector<T>::const_iterator iter_t;
pair<iter_t, iter_t> iMismatch;
iMismatch = mismatch (vbig1.begin() + 1, vbig1.end(), vbig2.begin() + 1);
assert (iMismatch.second <= vbig2.end());
if (iMismatch.first == vbig1.end())
cout << "works\n";
else
cout.format ("does not work: mismatch at %zd, 0x%lX != 0x%lX\n", abs_distance(vbig1.begin(), iMismatch.first), (unsigned long)(*iMismatch.first), (unsigned long)(*iMismatch.second));
}
static void TestAlgorithms (void)
{
static const int c_TestNumbers[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 11, 12, 13, 13, 14, 15, 16, 17, 18 };
const int* first = c_TestNumbers;
const int* last = first + VectorSize(c_TestNumbers);
intvec_t v, buf;
v.assign (first, last);
PrintVector (v);
cout << "swap(1,2)\n";
swap (v[0], v[1]);
PrintVector (v);
v.assign (first, last);
cout << "copy(0,8,9)\n";
copy (v.begin(), v.begin() + 8, v.begin() + 9);
PrintVector (v);
v.assign (first, last);
cout << "copy with back_inserter\n";
v.clear();
copy (first, last, back_inserter(v));
PrintVector (v);
v.assign (first, last);
cout << "copy with inserter\n";
v.clear();
copy (first, first + 5, inserter(v, v.begin()));
copy (first, first + 5, inserter(v, v.begin() + 3));
PrintVector (v);
v.assign (first, last);
cout << "copy_n(0,8,9)\n";
copy_n (v.begin(), 8, v.begin() + 9);
PrintVector (v);
v.assign (first, last);
cout << "copy_if(is_even)\n";
intvec_t v_even;
copy_if (v, back_inserter(v_even), &is_even);
PrintVector (v_even);
v.assign (first, last);
cout << "for_each(printint)\n{ ";
for_each (v, &printint);
cout << "}\n";
cout << "for_each(reverse_iterator, printint)\n{ ";
for_each (v.rbegin(), v.rend(), &printint);
cout << "}\n";
cout << "find(10)\n";
cout.format ("10 found at offset %zd\n", abs_distance (v.begin(), find (v, 10)));
cout << "count(13)\n";
cout.format ("%zu values of 13, %zu values of 18\n", count(v,13), count(v,18));
cout << "transform(sqr)\n";
transform (v, &sqr);
PrintVector (v);
v.assign (first, last);
cout << "replace(13,666)\n";
replace (v, 13, 666);
PrintVector (v);
v.assign (first, last);
cout << "fill(13)\n";
fill (v, 13);
PrintVector (v);
v.assign (first, last);
cout << "fill_n(5, 13)\n";
fill_n (v.begin(), 5, 13);
PrintVector (v);
v.assign (first, last);
cout << "fill 64083 uint8_t(0x41) ";
TestBigFill<uint8_t> (64083, 0x41);
cout << "fill 64083 uint16_t(0x4142) ";
TestBigFill<uint16_t> (64083, 0x4142);
cout << "fill 64083 uint32_t(0x41424344) ";
TestBigFill<uint32_t> (64083, 0x41424344);
cout << "fill 64083 float(0.4242) ";
TestBigFill<float> (64083, 0x4242f);
#if HAVE_INT64_T
cout << "fill 64083 uint64_t(0x4142434445464748) ";
TestBigFill<uint64_t> (64083, UINT64_C(0x4142434445464748));
#else
cout << "No 64bit types available on this platform\n";
#endif
cout << "copy 64083 uint8_t(0x41) ";
TestBigCopy<uint8_t> (64083, 0x41);
cout << "copy 64083 uint16_t(0x4142) ";
TestBigCopy<uint16_t> (64083, 0x4142);
cout << "copy 64083 uint32_t(0x41424344) ";
TestBigCopy<uint32_t> (64083, 0x41424344);
cout << "copy 64083 float(0.4242) ";
TestBigCopy<float> (64083, 0.4242f);
#if HAVE_INT64_T
cout << "copy 64083 uint64_t(0x4142434445464748) ";
TestBigCopy<uint64_t> (64083, UINT64_C(0x4142434445464748));
#else
cout << "No 64bit types available on this platform\n";
#endif
cout << "generate(genint)\n";
generate (v, &genint);
PrintVector (v);
v.assign (first, last);
cout << "rotate(4)\n";
rotate (v, 7);
rotate (v, -3);
PrintVector (v);
v.assign (first, last);
cout << "merge with (3,5,10,11,11,14)\n";
const int c_MergeWith[] = { 3,5,10,11,11,14 };
intvec_t vmerged;
merge (v.begin(), v.end(), VectorRange(c_MergeWith), back_inserter(vmerged));
PrintVector (vmerged);
v.assign (first, last);
cout << "inplace_merge with (3,5,10,11,11,14)\n";
v.insert (v.end(), VectorRange(c_MergeWith));
inplace_merge (v.begin(), v.end() - VectorSize(c_MergeWith), v.end());
PrintVector (v);
v.assign (first, last);
cout << "remove(13)\n";
remove (v, 13);
PrintVector (v);
v.assign (first, last);
cout << "remove (elements 3, 4, 6, 15, and 45)\n";
vector<uoff_t> toRemove;
toRemove.push_back (3);
toRemove.push_back (4);
toRemove.push_back (6);
toRemove.push_back (15);
toRemove.push_back (45);
typedef index_iterate<intvec_t::iterator, vector<uoff_t>::iterator> riiter_t;
riiter_t rfirst = index_iterator (v.begin(), toRemove.begin());
riiter_t rlast = index_iterator (v.begin(), toRemove.end());
remove (v, rfirst, rlast);
PrintVector (v);
v.assign (first, last);
cout << "unique\n";
unique (v);
PrintVector (v);
v.assign (first, last);
cout << "reverse\n";
reverse (v);
PrintVector (v);
v.assign (first, last);
cout << "lower_bound(10)\n";
PrintVector (v);
cout.format ("10 begins at position %zd\n", abs_distance (v.begin(), lower_bound (v, 10)));
v.assign (first, last);
cout << "upper_bound(10)\n";
PrintVector (v);
cout.format ("10 ends at position %zd\n", abs_distance (v.begin(), upper_bound (v, 10)));
v.assign (first, last);
cout << "equal_range(10)\n";
PrintVector (v);
TestEqualRange (v);
v.assign (first, last);
cout << "sort\n";
reverse (v);
PrintVector (v);
random_shuffle (v);
sort (v);
PrintVector (v);
v.assign (first, last);
cout << "stable_sort\n";
reverse (v);
PrintVector (v);
random_shuffle (v);
stable_sort (v);
PrintVector (v);
v.assign (first, last);
cout << "is_sorted\n";
random_shuffle (v);
const bool bNotSorted = is_sorted (v.begin(), v.end());
sort (v);
const bool bSorted = is_sorted (v.begin(), v.end());
cout << "unsorted=" << bNotSorted << ", sorted=" << bSorted << endl;
v.assign (first, last);
cout << "find_first_of\n";
static const int c_FFO[] = { 10000, -34, 14, 27 };
cout.format ("found 14 at position %zd\n", abs_distance (v.begin(), find_first_of (v.begin(), v.end(), VectorRange(c_FFO))));
v.assign (first, last);
static const int LC1[] = { 3, 1, 4, 1, 5, 9, 3 };
static const int LC2[] = { 3, 1, 4, 2, 8, 5, 7 };
static const int LC3[] = { 1, 2, 3, 4 };
static const int LC4[] = { 1, 2, 3, 4, 5 };
cout << "lexicographical_compare";
cout << "\nLC1 < LC2 == " << lexicographical_compare (VectorRange(LC1), VectorRange(LC2));
cout << "\nLC2 < LC2 == " << lexicographical_compare (VectorRange(LC2), VectorRange(LC2));
cout << "\nLC3 < LC4 == " << lexicographical_compare (VectorRange(LC3), VectorRange(LC4));
cout << "\nLC4 < LC1 == " << lexicographical_compare (VectorRange(LC4), VectorRange(LC1));
cout << "\nLC1 < LC4 == " << lexicographical_compare (VectorRange(LC1), VectorRange(LC4));
cout << "\nmax_element\n";
cout.format ("max element is %d\n", *max_element (v.begin(), v.end()));
v.assign (first, last);
cout << "min_element\n";
cout.format ("min element is %d\n", *min_element (v.begin(), v.end()));
v.assign (first, last);
cout << "partial_sort\n";
reverse (v);
partial_sort (v.begin(), v.iat(v.size() / 2), v.end());
PrintVector (v);
v.assign (first, last);
cout << "partial_sort_copy\n";
reverse (v);
buf.resize (v.size());
partial_sort_copy (v.begin(), v.end(), buf.begin(), buf.end());
PrintVector (buf);
v.assign (first, last);
cout << "partition\n";
partition (v.begin(), v.end(), &is_even);
PrintVector (v);
v.assign (first, last);
cout << "stable_partition\n";
stable_partition (v.begin(), v.end(), &is_even);
PrintVector (v);
v.assign (first, last);
cout << "next_permutation\n";
buf.resize (3);
iota (buf.begin(), buf.end(), 1);
PrintVector (buf);
while (next_permutation (buf.begin(), buf.end()))
PrintVector (buf);
cout << "prev_permutation\n";
reverse (buf);
PrintVector (buf);
while (prev_permutation (buf.begin(), buf.end()))
PrintVector (buf);
v.assign (first, last);
cout << "reverse_copy\n";
buf.resize (v.size());
reverse_copy (v.begin(), v.end(), buf.begin());
PrintVector (buf);
v.assign (first, last);
cout << "rotate_copy\n";
buf.resize (v.size());
rotate_copy (v.begin(), v.iat (v.size() / 3), v.end(), buf.begin());
PrintVector (buf);
v.assign (first, last);
static const int c_Search1[] = { 5, 6, 7, 8, 9 }, c_Search2[] = { 10, 10, 11, 14 };
cout << "search\n";
cout.format ("{5,6,7,8,9} at %zd\n", abs_distance (v.begin(), search (v.begin(), v.end(), VectorRange(c_Search1))));
cout.format ("{10,10,11,14} at %zd\n", abs_distance (v.begin(), search (v.begin(), v.end(), VectorRange(c_Search2))));
cout << "find_end\n";
cout.format ("{5,6,7,8,9} at %zd\n", abs_distance (v.begin(), find_end (v.begin(), v.end(), VectorRange(c_Search1))));
cout.format ("{10,10,11,14} at %zd\n", abs_distance (v.begin(), find_end (v.begin(), v.end(), VectorRange(c_Search2))));
cout << "search_n\n";
cout.format ("{14} at %zd\n", abs_distance (v.begin(), search_n (v.begin(), v.end(), 1, 14)));
cout.format ("{13,13} at %zd\n", abs_distance (v.begin(), search_n (v.begin(), v.end(), 2, 13)));
cout.format ("{10,10,10} at %zd\n", abs_distance (v.begin(), search_n (v.begin(), v.end(), 3, 10)));
v.assign (first, last);
cout << "includes\n";
static const int c_Includes[] = { 5, 14, 15, 18, 20 };
cout << "includes=" << includes (v.begin(), v.end(), VectorRange(c_Includes)-1);
cout << ", not includes=" << includes (v.begin(), v.end(), VectorRange(c_Includes));
cout << endl;
static const int c_Set1[] = { 1, 2, 3, 4, 5, 6 }, c_Set2[] = { 4, 4, 6, 7, 8 };
intvec_t::iterator setEnd;
cout << "set_difference\n";
v.resize (4);
setEnd = set_difference (VectorRange(c_Set1), VectorRange(c_Set2), v.begin());
PrintVector (v);
assert (setEnd == v.end());
cout << "set_symmetric_difference\n";
v.resize (7);
setEnd = set_symmetric_difference (VectorRange(c_Set1), VectorRange(c_Set2), v.begin());
PrintVector (v);
assert (setEnd == v.end());
cout << "set_intersection\n";
v.resize (2);
setEnd = set_intersection (VectorRange(c_Set1), VectorRange(c_Set2), v.begin());
PrintVector (v);
assert (setEnd == v.end());
cout << "set_union\n";
v.resize (9);
setEnd = set_union (VectorRange(c_Set1), VectorRange(c_Set2), v.begin());
PrintVector (v);
assert (setEnd == v.end());
v.assign (first, last);
}
StdBvtMain (TestAlgorithms)

132
extern/ustl/1.5/bvt/bvt05.std vendored Normal file
View File

@@ -0,0 +1,132 @@
{ 1 2 3 4 5 6 7 8 9 10 10 11 12 13 13 14 15 16 17 18 }
swap(1,2)
{ 2 1 3 4 5 6 7 8 9 10 10 11 12 13 13 14 15 16 17 18 }
copy(0,8,9)
{ 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 16 17 18 }
copy with back_inserter
{ 1 2 3 4 5 6 7 8 9 10 10 11 12 13 13 14 15 16 17 18 }
copy with inserter
{ 1 2 3 1 2 3 4 5 4 5 }
copy_n(0,8,9)
{ 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 16 17 18 }
copy_if(is_even)
{ 2 4 6 8 10 10 12 14 16 18 }
for_each(printint)
{ 1 2 3 4 5 6 7 8 9 10 10 11 12 13 13 14 15 16 17 18 }
for_each(reverse_iterator, printint)
{ 18 17 16 15 14 13 13 12 11 10 10 9 8 7 6 5 4 3 2 1 }
find(10)
10 found at offset 9
count(13)
2 values of 13, 1 values of 18
transform(sqr)
{ 1 4 9 16 25 36 49 64 81 100 100 121 144 169 169 196 225 256 289 324 }
replace(13,666)
{ 1 2 3 4 5 6 7 8 9 10 10 11 12 666 666 14 15 16 17 18 }
fill(13)
{ 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 }
fill_n(5, 13)
{ 13 13 13 13 13 6 7 8 9 10 10 11 12 13 13 14 15 16 17 18 }
fill 64083 uint8_t(0x41) works
fill 64083 uint16_t(0x4142) works
fill 64083 uint32_t(0x41424344) works
fill 64083 float(0.4242) works
fill 64083 uint64_t(0x4142434445464748) works
copy 64083 uint8_t(0x41) works
copy 64083 uint16_t(0x4142) works
copy 64083 uint32_t(0x41424344) works
copy 64083 float(0.4242) works
copy 64083 uint64_t(0x4142434445464748) works
generate(genint)
{ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 }
rotate(4)
{ 15 16 17 18 1 2 3 4 5 6 7 8 9 10 10 11 12 13 13 14 }
merge with (3,5,10,11,11,14)
{ 1 2 3 3 4 5 5 6 7 8 9 10 10 10 11 11 11 12 13 13 14 14 15 16 17 18 }
inplace_merge with (3,5,10,11,11,14)
{ 1 2 3 3 4 5 5 6 7 8 9 10 10 10 11 11 11 12 13 13 14 14 15 16 17 18 }
remove(13)
{ 1 2 3 4 5 6 7 8 9 10 10 11 12 14 15 16 17 18 }
remove (elements 3, 4, 6, 15, and 45)
{ 1 2 3 6 8 9 10 10 11 12 13 13 15 16 17 18 }
unique
{ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 }
reverse
{ 18 17 16 15 14 13 13 12 11 10 10 9 8 7 6 5 4 3 2 1 }
lower_bound(10)
{ 1 2 3 4 5 6 7 8 9 10 10 11 12 13 13 14 15 16 17 18 }
10 begins at position 9
upper_bound(10)
{ 1 2 3 4 5 6 7 8 9 10 10 11 12 13 13 14 15 16 17 18 }
10 ends at position 11
equal_range(10)
{ 1 2 3 4 5 6 7 8 9 10 10 11 12 13 13 14 15 16 17 18 }
Range of 10 is { 9, 11 }
Range of 0 is { 0, 0 }
Range of 100 is { 20, 20 }
sort
{ 18 17 16 15 14 13 13 12 11 10 10 9 8 7 6 5 4 3 2 1 }
{ 1 2 3 4 5 6 7 8 9 10 10 11 12 13 13 14 15 16 17 18 }
stable_sort
{ 18 17 16 15 14 13 13 12 11 10 10 9 8 7 6 5 4 3 2 1 }
{ 1 2 3 4 5 6 7 8 9 10 10 11 12 13 13 14 15 16 17 18 }
is_sorted
unsorted=false, sorted=true
find_first_of
found 14 at position 15
lexicographical_compare
LC1 < LC2 == true
LC2 < LC2 == false
LC3 < LC4 == true
LC4 < LC1 == true
LC1 < LC4 == false
max_element
max element is 18
min_element
min element is 1
partial_sort
{ 1 2 3 4 5 6 7 8 9 10 10 11 12 13 13 14 15 16 17 18 }
partial_sort_copy
{ 1 2 3 4 5 6 7 8 9 10 10 11 12 13 13 14 15 16 17 18 }
partition
{ 2 4 6 8 10 10 12 14 16 18 1 3 5 7 9 11 13 13 15 17 }
stable_partition
{ 2 4 6 8 10 10 12 14 16 18 1 3 5 7 9 11 13 13 15 17 }
next_permutation
{ 1 2 3 }
{ 1 3 2 }
{ 2 1 3 }
{ 2 3 1 }
{ 3 1 2 }
{ 3 2 1 }
prev_permutation
{ 3 2 1 }
{ 3 1 2 }
{ 2 3 1 }
{ 2 1 3 }
{ 1 3 2 }
{ 1 2 3 }
reverse_copy
{ 18 17 16 15 14 13 13 12 11 10 10 9 8 7 6 5 4 3 2 1 }
rotate_copy
{ 7 8 9 10 10 11 12 13 13 14 15 16 17 18 1 2 3 4 5 6 }
search
{5,6,7,8,9} at 4
{10,10,11,14} at 20
find_end
{5,6,7,8,9} at 4
{10,10,11,14} at 20
search_n
{14} at 15
{13,13} at 13
{10,10,10} at 20
includes
includes=true, not includes=false
set_difference
{ 1 2 3 5 }
set_symmetric_difference
{ 1 2 3 4 5 7 8 }
set_intersection
{ 4 6 }
set_union
{ 1 2 3 4 4 5 6 7 8 }

59
extern/ustl/1.5/bvt/bvt06.cc vendored Normal file
View File

@@ -0,0 +1,59 @@
// This file is part of the uSTL library, an STL implementation.
//
// Copyright (c) 2005 by Mike Sharov <msharov@users.sourceforge.net>
// This file is free software, distributed under the MIT License.
#include "stdtest.h"
void PrintBlock (const cmemlink& l)
{
const int* numbers = reinterpret_cast<const int*>(l.begin());
const size_t nNumbers = l.size() / sizeof(int);
for (size_t i = 0; i < nNumbers; ++ i)
cout << numbers[i] << ' ';
cout << endl;
}
void TestObjectVector (void)
{
vector<memblock> v;
const size_t nNumbers = 1000;
int numbers [nNumbers];
const size_t nLinks = 10;
cmemlink links [nLinks];
for (size_t i = 0; i < nNumbers; ++ i)
numbers[i] = i;
uoff_t offset = 0;
for (size_t l = 0; l < nLinks; ++ l) {
links[l].link (numbers + offset, l * sizeof(int));
offset += l;
v.push_back (memblock(links[l]));
}
cout.format ("---\nvector<memblock> of %zu elements:\n---\n", v.size());
for_each (v.begin(), v.end(), &PrintBlock);
cout.format ("---\nsize() = %zu, max_size() = ", v.size());
if (v.max_size() == SIZE_MAX / sizeof(memblock))
cout << "SIZE_MAX/elsize";
else
cout << v.max_size();
static const char tf[2][6]={"false","true"};
cout.format (", empty() = %s\n", tf[v.empty()]);
v.push_back (memblock(5));
cout.format ("back()->size() = %zu\n", v.back().size());
v.back().resize (40);
cout.format ("back()->size() = %zu\n", v.back().size());
v.pop_back();
PrintBlock (v.back());
vector<memblock> cache;
cache.assign (v.begin(), v.end());
v.clear();
v.assign (cache.begin(), cache.end());
v.erase (v.begin() + 5, 2);
v.erase (v.end() - 1, 1);
v.erase (v.end(), streamsize(0));
cout.format ("---\nvector of %zu elements backwards:\n---\n", v.size());
for_each (v.rbegin(), v.rend(), &PrintBlock);
cout << "---\n";
}
StdBvtMain (TestObjectVector)

29
extern/ustl/1.5/bvt/bvt06.std vendored Normal file
View File

@@ -0,0 +1,29 @@
---
vector<memblock> of 10 elements:
---
0
1 2
3 4 5
6 7 8 9
10 11 12 13 14
15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31 32 33 34 35
36 37 38 39 40 41 42 43 44
---
size() = 10, max_size() = SIZE_MAX/elsize, empty() = false
back()->size() = 5
back()->size() = 40
36 37 38 39 40 41 42 43 44
---
vector of 7 elements backwards:
---
28 29 30 31 32 33 34 35
21 22 23 24 25 26 27
6 7 8 9
3 4 5
1 2
0
---

135
extern/ustl/1.5/bvt/bvt07.cc vendored Normal file
View File

@@ -0,0 +1,135 @@
// This file is part of the uSTL library, an STL implementation.
//
// Copyright (c) 2005 by Mike Sharov <msharov@users.sourceforge.net>
// This file is free software, distributed under the MIT License.
#include "stdtest.h"
void MyFormat (const char* fmt, ...) __attribute__((__format__(__printf__,1,2)));
void TestString (void)
{
static const char c_TestString1[] = "123456789012345678901234567890";
static const char c_TestString2[] = "abcdefghijklmnopqrstuvwxyz";
static const char c_TestString3[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string s1 (c_TestString1);
string s2 (VectorRange (c_TestString2));
string s3 (s1);
cout << s1 << endl;
cout << s2 << endl;
cout << s3 << endl;
s3.reserve (48);
s3.resize (20);
uoff_t i;
for (i = 0; i < s3.length(); ++ i)
s3.at(i) = s3.at(i);
for (i = 0; i < s3.length(); ++ i)
s3[i] = s3[i];
cout.format ("%s\ns3.size() = %zu, max_size() = ", s3.c_str(), s3.size());
if (s3.max_size() == SIZE_MAX - 1)
cout << "(SIZE_MAX/elsize)-1";
else
cout << s3.max_size();
cout.format (", capacity() = %zu\n", s3.capacity());
s1.unlink();
s1 = c_TestString2;
s1 += c_TestString3;
s1 += '$';
cout << s1 << endl;
s1 = "Hello";
s2.unlink();
s2 = "World";
s3 = s1 + s2;
cout << s3 << endl;
s3 = "Concatenated " + s1 + s2 + " string.";
cout << s3 << endl;
if (s1 < s2)
cout << "s1 < s2\n";
if (s1 == s1)
cout << "s1 == s1\n";
if (s1[0] != s1[0])
cout << "s1[0] != s1[0]\n";
string s4;
s4.link (s1);
if (s1 == s4)
cout << "s1 == s4\n";
s1 = c_TestString1;
string s5 (s1.begin() + 4, s1.begin() + 4 + 5);
string s6 (s1.begin() + 4, s1.begin() + 4 + 5);
if (s5 == s6)
cout.format ("%s == %s\n", s5.c_str(), s6.c_str());
string tail (s1.begin() + 7, s1.end());
cout.format ("&s1[7] = %s\n", tail.c_str());
cout.format ("initial:\t\t%s\n", s1.c_str());
cout << "erase(5,find(9)-5)\t";
s1.erase (5, s1.find ('9')-5);
cout << s1 << endl;
cout << "erase(5,5)\t\t";
s1.erase (s1.begin() + 5, 2U);
s1.erase (5, 3);
assert (!*s1.end());
cout << s1 << endl;
cout << "push_back('x')\t\t";
s1.push_back ('x');
assert (!*s1.end());
cout << s1 << endl;
cout << "pop_back()\n";
s1.pop_back();
assert (!*s1.end());
cout << "insert(10,#)\t\t";
s1.insert (s1.begin() + 10, '#');
assert (!*s1.end());
cout << s1 << endl;
cout << "replace(0,5,@)\t\t";
s1.replace (s1.begin(), s1.begin() + 5, 1, '@');
assert (!*s1.end());
cout << s1 << endl;
s1 = c_TestString1;
cout.format ("8 found at %zu\n", s1.find ('8'));
cout.format ("9 found at %zu\n", s1.find ("9"));
cout.format ("7 rfound at %zu\n", s1.rfind ('7'));
cout.format ("7 rfound again at %zu\n", s1.rfind ('7', s1.rfind ('7') - 1));
cout.format ("67 rfound at %zu\n", s1.rfind ("67"));
if (s1.rfind("X") == string::npos)
cout << "X was not rfound\n";
else
cout.format ("X rfound at %zu\n", s1.rfind ("X"));
uoff_t poundfound = s1.find ("#");
if (poundfound != string::npos)
cout.format ("# found at %zu\n", poundfound);
cout.format ("[456] found at %zu\n", s1.find_first_of ("456"));
cout.format ("[456] last found at %zu\n", s1.find_last_of ("456"));
s2.clear();
assert (!*s2.end());
if (s2.empty())
cout.format ("s2 is empty [%s], capacity %zu bytes\n", s2.c_str(), s2.capacity());
s2.format ("<const] %d, %s, 0x%08X", 42, "[rfile>", 0xDEADBEEF);
cout.format ("<%zu bytes of %zu> Format '%s'\n", s2.length(), s2.capacity(), s2.c_str());
MyFormat ("'<const] %d, %s, 0x%08X'", 42, "[rfile>", 0xDEADBEEF);
cout.format ("hash_value(s2) = %08X, string::hash(s2) = %08X\n", hash_value (s2.begin()), string::hash (s2.begin(), s2.end()));
}
void MyFormat (const char* fmt, ...)
{
string buf;
simd::reset_mmx();
va_list args;
va_start (args, fmt);
buf.vformat (fmt, args);
cout.format ("Custom vararg MyFormat: %s\n", buf.c_str());
va_end (args);
}
StdBvtMain (TestString)

32
extern/ustl/1.5/bvt/bvt07.std vendored Normal file
View File

@@ -0,0 +1,32 @@
123456789012345678901234567890
abcdefghijklmnopqrstuvwxyz
123456789012345678901234567890
12345678901234567890
s3.size() = 20, max_size() = (SIZE_MAX/elsize)-1, capacity() = 48
abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$
HelloWorld
Concatenated HelloWorld string.
s1 < s2
s1 == s1
s1 == s4
56789 == 56789
&s1[7] = 89012345678901234567890
initial: 123456789012345678901234567890
erase(5,find(9)-5) 123459012345678901234567890
erase(5,5) 1234545678901234567890
push_back('x') 1234545678901234567890x
pop_back()
insert(10,#) 1234545678#901234567890
replace(0,5,@) @45678#901234567890
8 found at 7
9 found at 8
7 rfound at 26
7 rfound again at 16
67 rfound at 25
X was not rfound
[456] found at 3
[456] last found at 25
s2 is empty [], capacity 5 bytes
<31 bytes of 31> Format '<const] 42, [rfile>, 0xDEADBEEF'
Custom vararg MyFormat: '<const] 42, [rfile>, 0xDEADBEEF'
hash_value(s2) = 95A714F3, string::hash(s2) = 95A714F3

57
extern/ustl/1.5/bvt/bvt08.cc vendored Normal file
View File

@@ -0,0 +1,57 @@
// This file is part of the uSTL library, an STL implementation.
//
// Copyright (c) 2005 by Mike Sharov <msharov@users.sourceforge.net>
// This file is free software, distributed under the MIT License.
#include "stdtest.h"
inline void PrintString (const string& str)
{
cout << str << endl;
}
void TestStringVector (void)
{
vector<string> v;
vector<string>::iterator bogusi = find (v, string("bogus"));
if (bogusi != v.end())
cout << "bogus found at position " << bogusi - v.begin() << endl;
v.push_back (string("Hello world!"));
v.push_back (string("Hello again!"));
v.push_back (string("element3"));
v.push_back (string("element4"));
v.push_back (string("element5_long_element5"));
for_each (v, &PrintString);
if (!(v[2] == string("element3")))
cout << "operator== failed" << endl;
vector<string>::iterator el3i = find (v, string("element3"));
if (el3i != v.end())
cout << *el3i << " found at position " << el3i - v.begin() << endl;
bogusi = find (v, string("bogus"));
if (bogusi != v.end())
cout << *bogusi << " found at position " << bogusi - v.begin()<< endl;
vector<string> v2;
v2 = v;
v = v2;
v.erase (v.end(), v.end());
cout << "After erase (end,end):" << endl;
for_each (v, &PrintString);
v = v2;
v.erase (v.begin() + 2, 2);
cout << "After erase (2,2):" << endl;
for_each (v, &PrintString);
v = v2;
v.pop_back();
cout << "After pop_back():" << endl;
for_each (v, &PrintString);
v = v2;
v.insert (v.begin() + 1, v2.begin() + 1, v2.begin() + 1 + 3);
cout << "After insert(1,1,3):" << endl;
for_each (v, &PrintString);
}
StdBvtMain (TestStringVector)

30
extern/ustl/1.5/bvt/bvt08.std vendored Normal file
View File

@@ -0,0 +1,30 @@
Hello world!
Hello again!
element3
element4
element5_long_element5
element3 found at position 2
After erase (end,end):
Hello world!
Hello again!
element3
element4
element5_long_element5
After erase (2,2):
Hello world!
Hello again!
element5_long_element5
After pop_back():
Hello world!
Hello again!
element3
element4
After insert(1,1,3):
Hello world!
Hello again!
element3
element4
Hello again!
element3
element4
element5_long_element5

84
extern/ustl/1.5/bvt/bvt09.cc vendored Normal file
View File

@@ -0,0 +1,84 @@
// This file is part of the uSTL library, an STL implementation.
//
// Copyright (c) 2005 by Mike Sharov <msharov@users.sourceforge.net>
// This file is free software, distributed under the MIT License.
#include "stdtest.h"
void TestStringStreams (void)
{
const unsigned char magic_Char = 'c';
const unsigned short magic_Short = 1234;
const long magic_Int = -12345678;
const unsigned long magic_UInt = 12345678;
const float magic_Float = 123.45678;
const double magic_Double = 123456789123456.789;
const bool magic_Bool = true;
char c = magic_Char;
unsigned char uc = magic_Char;
int i = magic_Int;
short si = magic_Short;
long li = magic_Int;
unsigned int ui = magic_UInt;
unsigned short usi = magic_Short;
unsigned long uli = magic_UInt;
float f = magic_Float;
double d = magic_Double;
bool bv = magic_Bool;
ostringstream os;
os << c << endl;
os << uc << endl;
os << bv << endl;
os << i << endl;
os << ui << endl;
os << li << endl;
os << uli << endl;
os << f << endl;
os << d << endl;
os << si << endl;
os << usi << endl << ends;
os.flush();
cout << os.pos() << " bytes written" << endl;
c = 0;
uc = 0;
bv = false;
i = ui = li = uli = 0;
f = 0; d = 0;
si = usi = 0;
istringstream is (os.str());
is >> c;
is >> uc;
is >> bv;
is >> i;
is >> ui;
is >> li;
is >> uli;
is >> f;
is >> d;
is >> si;
is >> usi;
cout << "Values:" << endl;
cout.format ("char: '%c'\n", static_cast<int>(c));
cout.format ("u_char: '%c'\n", static_cast<int>(uc));
cout.format ("bool: %d\n", static_cast<int>(bv));
cout.format ("int: %d\n", i);
cout.format ("u_int: %d\n", ui);
cout.format ("long: %ld\n", li);
cout.format ("u_long: %ld\n", uli);
cout.format ("float: %.2f\n", f);
cout.format ("double: %.2f\n", d);
cout.format ("short: %d\n", static_cast<int>(si));
cout.format ("u_short: %d\n", static_cast<int>(usi));
cout << endl;
cout << "Dump:" << endl;
cout << os.str().cdata() << endl;
cout << endl;
}
StdBvtMain (TestStringStreams)

28
extern/ustl/1.5/bvt/bvt09.std vendored Normal file
View File

@@ -0,0 +1,28 @@
84 bytes written
Values:
char: 'c'
u_char: 'c'
bool: 1
int: -12345678
u_int: 12345678
long: -12345678
u_long: 12345678
float: 123.46
double: 123456789123456.78
short: 1234
u_short: 1234
Dump:
c
c
true
-12345678
12345678
-12345678
12345678
123.46
123456789123456.78
1234
1234

171
extern/ustl/1.5/bvt/bvt10.cc vendored Normal file
View File

@@ -0,0 +1,171 @@
// This file is part of the uSTL library, an STL implementation.
//
// Copyright (c) 2005 by Mike Sharov <msharov@users.sourceforge.net>
// This file is free software, distributed under the MIT License.
#include "stdtest.h"
template <typename Container>
void PrintVector (const Container& ctr)
{
cout << "{";
foreach (typename Container::const_iterator, i, ctr)
cout << ' ' << *i;
cout << " }\n";
}
class A {
public:
A (int dv = 6) : m_v1 (0), m_v (dv) {}
int addsix (int i) { return (i + m_v); }
void addsix (int& i) const { i += m_v; }
void addtosix (int i) { m_v += i; }
inline void text_write (ostringstream& os) const { os << m_v; }
public:
int m_v1;
int m_v;
};
INTEGRAL_STREAMABLE(A)
TEXT_STREAMABLE(A)
void TestFunctors (void)
{
vector<int> v;
v.resize (20);
fill (v, 2);
foreach (vector<int>::iterator, i, v)
*i -= distance(v.begin(), i) & 1;
vector<int> v1 (v);
cout << "start:\t\t\t";
PrintVector (v);
v = v1;
cout << "plus:\t\t\t";
transform (v, v.begin(), v.begin(), plus<int>());
PrintVector (v);
v = v1;
cout << "minus:\t\t\t";
transform (v, v.begin(), v.begin(), minus<int>());
PrintVector (v);
v = v1;
cout << "divides:\t\t";
transform (v, v.begin(), v.begin(), divides<int>());
PrintVector (v);
v = v1;
cout << "multiplies:\t\t";
transform (v, v.begin(), v.begin(), multiplies<int>());
PrintVector (v);
v = v1;
cout << "modulus:\t\t";
transform (v, v.begin(), v.begin(), modulus<int>());
PrintVector (v);
v = v1;
cout << "logical_and:\t\t";
transform (v, v.begin(), v.begin(), logical_and<int>());
PrintVector (v);
v = v1;
cout << "logical_or:\t\t";
transform (v, v.begin(), v.begin(), logical_or<int>());
PrintVector (v);
v = v1;
cout << "equal_to:\t\t";
transform (v, v.begin(), v.begin(), equal_to<int>());
PrintVector (v);
v = v1;
cout << "not_equal_to:\t\t";
transform (v, v.begin(), v.begin(), not_equal_to<int>());
PrintVector (v);
v = v1;
cout << "greater:\t\t";
transform (v, v.begin(), v.begin(), greater<int>());
PrintVector (v);
v = v1;
cout << "less:\t\t\t";
transform (v, v.begin(), v.begin(), less<int>());
PrintVector (v);
v = v1;
cout << "greater_equal:\t\t";
transform (v, v.begin(), v.begin(), greater_equal<int>());
PrintVector (v);
v = v1;
cout << "less_equal:\t\t";
transform (v, v.begin(), v.begin(), less_equal<int>());
PrintVector (v);
v = v1;
cout << "compare:\t\t";
transform (v, v.begin(), v.begin(), compare<int>());
PrintVector (v);
v = v1;
cout << "negate:\t\t\t";
transform (v, negate<int>());
PrintVector (v);
v = v1;
cout << "logical_not:\t\t";
transform (v, logical_not<int>());
PrintVector (v);
v = v1;
cout << "unary_neg(negate):\t";
transform (v, unary_negator(negate<int>()));
PrintVector (v);
v = v1;
cout << "binder1st(plus,5):\t";
transform (v, bind1st(plus<int>(), 5));
PrintVector (v);
v = v1;
cout << "binder2nd(minus,1):\t";
transform (v, bind2nd(minus<int>(), 1));
PrintVector (v);
v = v1;
cout << "compose1(-,+5):\t\t";
transform (v, compose1 (negate<int>(), bind2nd(plus<int>(), 5)));
PrintVector (v);
v = v1;
cout << "compose1(-,-4):\t\t";
transform (v, compose1 (negate<int>(), bind2nd(minus<int>(), 4)));
PrintVector (v);
v = v1;
cout << "compose2(/,+6,-4):\t";
transform (v, compose2 (divides<int>(), bind2nd(plus<int>(), 6), bind2nd(minus<int>(), 4)));
PrintVector (v);
cout << "mem_var(plus,6):\t";
vector<A> av;
for (uoff_t i = 0; i < 20; ++ i)
av.push_back (A(i));
transform (av, mem_var1(&A::m_v, bind2nd(plus<int>(), 6)));
PrintVector (av);
vector<A>::iterator found = find_if (av, mem_var_equal_to(&A::m_v, 14));
cout << "14 found at position " << found - av.begin() << endl;
found = lower_bound (av.begin(), av.end(), 18, mem_var_less(&A::m_v));
cout << "18 found at position " << found - av.begin() << endl;
cout << "add next:\t\t";
transform (av.begin(), av.end() - 1, av.begin() + 1, av.begin(), mem_var2(&A::m_v, plus<int>()));
PrintVector (av);
}
StdBvtMain (TestFunctors)

27
extern/ustl/1.5/bvt/bvt10.std vendored Normal file
View File

@@ -0,0 +1,27 @@
start: { 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 }
plus: { 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 }
minus: { 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 }
divides: { 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 }
multiplies: { 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 }
modulus: { 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 }
logical_and: { 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 }
logical_or: { 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 }
equal_to: { 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 }
not_equal_to: { 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 }
greater: { 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 }
less: { 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 }
greater_equal: { 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 }
less_equal: { 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 }
compare: { 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 }
negate: { -2 -1 -2 -1 -2 -1 -2 -1 -2 -1 -2 -1 -2 -1 -2 -1 -2 -1 -2 -1 }
logical_not: { 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 }
unary_neg(negate): { 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 }
binder1st(plus,5): { 7 6 7 6 7 6 7 6 7 6 7 6 7 6 7 6 7 6 7 6 }
binder2nd(minus,1): { 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 }
compose1(-,+5): { -7 -6 -7 -6 -7 -6 -7 -6 -7 -6 -7 -6 -7 -6 -7 -6 -7 -6 -7 -6 }
compose1(-,-4): { 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 }
compose2(/,+6,-4): { -4 -2 -4 -2 -4 -2 -4 -2 -4 -2 -4 -2 -4 -2 -4 -2 -4 -2 -4 -2 }
mem_var(plus,6): { 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 }
14 found at position 8
18 found at position 12
add next: { 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 25 }

36
extern/ustl/1.5/bvt/bvt11.cc vendored Normal file
View File

@@ -0,0 +1,36 @@
// This file is part of the uSTL library, an STL implementation.
//
// Copyright (c) 2005 by Mike Sharov <msharov@users.sourceforge.net>
// This file is free software, distributed under the MIT License.
#include "stdtest.h"
void PrintVector (const int* first, const int* last)
{
cout << "{";
while (first < last)
cout << ' ' << *first++;
cout << " }" << endl;
}
void TestSetAndMultiset (void)
{
const int vv[] = { 1, 8, 9, 2, 3, 1, 1, 4, 6, 1, 3, 4 };
set<int> v (VectorRange (vv));
multiset<int> mv (VectorRange (vv));
cout << "set:\t\t";
PrintVector (v.begin(), v.end());
cout << "erase(3):\t";
v.erase (3);
PrintVector (v.begin(), v.end());
cout << "multiset:\t";
PrintVector (mv.begin(), mv.end());
cout << "count(1) = " << mv.count(1) << endl;
cout << "find(4) = " << lower_bound (mv, 4) - mv.begin() << endl;
cout << "find(5) = " << binary_search (mv, 5) << endl;
cout << "erase(3):\t";
mv.erase (3);
PrintVector (mv.begin(), mv.end());
}
StdBvtMain (TestSetAndMultiset)

7
extern/ustl/1.5/bvt/bvt11.std vendored Normal file
View File

@@ -0,0 +1,7 @@
set: { 1 2 3 4 6 8 9 }
erase(3): { 1 2 4 6 8 9 }
multiset: { 1 1 1 1 2 3 3 4 4 6 8 9 }
count(1) = 4
find(4) = 7
find(5) = false
erase(3): { 1 1 1 1 2 4 4 6 8 9 }

81
extern/ustl/1.5/bvt/bvt12.cc vendored Normal file
View File

@@ -0,0 +1,81 @@
// This file is part of the uSTL library, an STL implementation.
//
// Copyright (c) 2005 by Mike Sharov <msharov@users.sourceforge.net>
// This file is free software, distributed under the MIT License.
#include "stdtest.h"
void ObjectSerialization (void)
{
#define RW(stream) rws[stream.pos() == expect]
const void* pBufC = NULL;
void* pBuf = NULL;
memblock buffer;
string testString ("TestString");
const string* pStrC = NULL;
string* pStr = NULL;
vector<uint16_t> tv (7);
static const char* rws[2] = { "wrong", "right" };
const size_t bufSize = stream_size_of(pBufC) +
stream_size_of(pBuf) +
Align(stream_size_of(testString)) +
stream_size_of(pStrC) +
stream_size_of(pStr) +
stream_size_of(tv);
buffer.resize (bufSize);
pBufC = buffer.cdata();
pBuf = buffer.data();
uoff_t expect = 0;
ostream os (buffer);
os << pBufC; expect += stream_size_of(pBufC);
cout << "Write const void*, pos is " << RW(os) << endl;
os << pBuf; expect += stream_size_of(pBuf);
cout << "Write void*, pos is " << RW(os) << endl;
os << testString; expect += stream_size_of(testString);
cout << "Write string, pos is " << RW(os) << endl;
os.align(); expect = Align (expect);
os << const_cast<const string*>(&testString); expect += stream_size_of(&testString);
cout << "Write const string*, pos is " << RW(os) << endl;
os << &testString; expect += stream_size_of(&testString);
cout << "Write string*, pos is " << RW(os) << endl;
os << tv; expect += stream_size_of(tv);
cout << "Write vector<uint16_t>(7), pos is " << RW(os) << endl;
if (os.pos() != bufSize)
cout << "Incorrect number of bytes written: " << os.pos() << " of " << bufSize << endl;
istream is (buffer);
expect = 0;
is >> pBufC;
expect += stream_size_of(pBufC);
cout << "Read const void*, pos is " << RW(is);
cout << ", value is " << rws[pBufC == buffer.cdata()] << endl;
is >> pBuf;
expect += stream_size_of(pBuf);
cout << "Read void*, pos is " << RW(is);
cout << ", value is " << rws[pBuf == buffer.cdata()] << endl;
testString.clear();
is >> testString;
expect += stream_size_of(testString);
cout << "Read string, pos is " << RW(is) << ", value is " << testString << endl;
is.align();
expect = Align (expect);
is >> pStrC;
expect += stream_size_of(pStrC);
cout << "Read const string*, pos is " << RW(is);
cout << ", value is " << rws[pStrC == &testString] << endl;
is >> pStr;
expect += stream_size_of(pStr);
cout << "Read string*, pos is " << RW(is);
cout << ", value is " << rws[pStr == &testString] << endl;
vector<uint16_t> rv;
is >> rv;
expect += stream_size_of(rv);
cout << "Read vector<uint16_t>(" << rv.size() << "), pos is " << RW(is);
cout << ", value is " << rws[rv == tv] << endl;
if (is.pos() != bufSize)
cout << "Incorrect number of bytes read: " << is.pos() << " of " << bufSize << endl;
}
StdBvtMain (ObjectSerialization)

12
extern/ustl/1.5/bvt/bvt12.std vendored Normal file
View File

@@ -0,0 +1,12 @@
Write const void*, pos is right
Write void*, pos is right
Write string, pos is right
Write const string*, pos is right
Write string*, pos is right
Write vector<uint16_t>(7), pos is right
Read const void*, pos is right, value is right
Read void*, pos is right, value is right
Read string, pos is right, value is TestString
Read const string*, pos is right, value is right
Read string*, pos is right, value is right
Read vector<uint16_t>(7), pos is right, value is right

36
extern/ustl/1.5/bvt/bvt13.cc vendored Normal file
View File

@@ -0,0 +1,36 @@
// "Testing string reads" 12345678 4321 0x78675645 1.234567890123456
// (the above line is the input to this test, so must be at the beginning)
//
// This file is part of the uSTL library, an STL implementation.
//
// Copyright (c) 2005 by Mike Sharov <msharov@users.sourceforge.net>
// This file is free software, distributed under the MIT License.
#include "stdtest.h"
#include <stdio.h>
void TestCoutCinCerr (void)
{
string testStr;
cin >> testStr;
if (testStr != "//") {
cout.format ("You must put bvt13.cc on stdin (read \"%s\")\n", testStr.c_str());
return;
}
uint32_t n1 = 0, n3 = 0;
uint16_t n2 = 0;
double f1 = 0.0;
cin >> testStr >> n1 >> n2 >> n3 >> f1;
cout << testStr << endl;
cout << "A string printed to stdout\n";
cout.format ("%d %s: %d, %hd, 0x%08X, %1.15f\n", 4, "numbers", n1, n2, n3, f1);
string testString;
testString.format ("A ustl::string object printed %d times\n", 3);
for (int i = 0; i < 3; ++ i)
cout << testString;
cout.flush();
fprintf (stderr, "All ");
cerr << "done.\n";
}
StdBvtMain (TestCoutCinCerr)

7
extern/ustl/1.5/bvt/bvt13.std vendored Normal file
View File

@@ -0,0 +1,7 @@
Testing string reads
A string printed to stdout
4 numbers: 12345678, 4321, 0x78675645, 1.234567890123456
A ustl::string object printed 3 times
A ustl::string object printed 3 times
A ustl::string object printed 3 times
All done.

59
extern/ustl/1.5/bvt/bvt14.cc vendored Normal file
View File

@@ -0,0 +1,59 @@
// This file is part of the uSTL library, an STL implementation.
//
// Copyright (c) 2005 by Mike Sharov <msharov@users.sourceforge.net>
// This file is free software, distributed under the MIT License.
#include "stdtest.h"
void TestMap (void)
{
typedef map<string,int> monthmap_t;
monthmap_t months;
months["january"] = 31;
months["february"] = 28;
months["march"] = 31;
months["april"] = 30;
months["may"] = 31;
months["june"] = 30;
months["july"] = 31;
months["august"] = 31;
months["september"] = 30;
months["october"] = 31;
months["november"] = 30;
months["december"] = 31;
const monthmap_t& cmonths = months;
cout << "There are " << cmonths["january"] << " days in january." << endl;
cout << "There are " << cmonths["september"] << " days in september." << endl;
cout << "There are " << cmonths["december"] << " days in december." << endl;
monthmap_t::const_iterator found_may = months.find ("may");
cout << found_may->first << " found at index " << found_may - months.begin() << endl;
cout << "Alphabetical listing:" << endl;
monthmap_t::const_iterator i;
for (i = months.begin(); i < months.end(); ++ i)
cout << i->first << " has " << i->second << " days." << endl;
monthmap_t mcopy (months);
mcopy.erase ("may");
cout << "After erasing may:" << endl;
for (i = mcopy.begin(); i < mcopy.end(); ++ i)
cout << i->first << " ";
cout << endl;
mcopy.assign (months.begin(), months.end() - 1);
mcopy.erase (mcopy.begin() + 1, mcopy.begin() + 4);
cout << "After erasing months 2, 3, 4, and the last one:" << endl;
for (i = mcopy.begin(); i < mcopy.end(); ++ i)
cout << i->first << " ";
cout << endl;
mcopy = months;
monthmap_t::iterator frob = mcopy.insert (mcopy.begin(), make_pair (string("frobuary"), 42));
cout << "After inserting " << frob->first << "," << frob->second << ":" << endl;
for (i = mcopy.begin(); i < mcopy.end(); ++ i)
cout << i->first << " ";
cout << endl;
}
StdBvtMain (TestMap)

23
extern/ustl/1.5/bvt/bvt14.std vendored Normal file
View File

@@ -0,0 +1,23 @@
There are 31 days in january.
There are 30 days in september.
There are 31 days in december.
may found at index 8
Alphabetical listing:
april has 30 days.
august has 31 days.
december has 31 days.
february has 28 days.
january has 31 days.
july has 31 days.
june has 30 days.
march has 31 days.
may has 31 days.
november has 30 days.
october has 31 days.
september has 30 days.
After erasing may:
april august december february january july june march november october september
After erasing months 2, 3, 4, and the last one:
april january july june march may november october
After inserting frobuary,42:
april august december february frobuary january july june march may november october september

57
extern/ustl/1.5/bvt/bvt15.cc vendored Normal file
View File

@@ -0,0 +1,57 @@
// This file is part of the uSTL library, an STL implementation.
//
// Copyright (c) 2005 by Mike Sharov <msharov@users.sourceforge.net>
// This file is free software, distributed under the MIT License.
#include "stdtest.h"
typedef multimap<int,string> empmap_t;
typedef empmap_t::const_iterator citer_t;
void PrintEntries (citer_t first, citer_t last)
{
for (citer_t i = first; i < last; ++ i)
cout << i->second << "\t- $" << i->first << endl;
}
inline void PrintEntries (const empmap_t& m) { PrintEntries (m.begin(), m.end()); }
void TestMultiMap (void)
{
empmap_t employees;
employees.insert (make_pair (27000, string("Dave")));
employees.insert (make_pair (27000, string("Jim")));
employees.insert (make_pair (99000, string("BigBoss")));
employees.insert (make_pair (47000, string("Gail")));
employees.insert (make_pair (15000, string("Dumb")));
employees.insert (make_pair (47000, string("Barbara")));
employees.insert (make_pair (47000, string("Mary")));
cout << "As-inserted listing:\n";
PrintEntries (employees);
cout << "Alphabetical listing:\n";
sort (employees);
PrintEntries (employees);
empmap_t::range_t middles = employees.equal_range (47000);
cout << "Employees making $" << middles.first->first << ":";
empmap_t::const_iterator i;
for (i = middles.first; i < middles.second; ++ i)
cout << " " << i->second;
cout << endl;
cout << employees.find(27000)->second << " makes $27000\n";
cout << "There are " << employees.count (27000) << " low-paid employees\n";
cout << "Firing all low-paid employees:\n";
employees.erase (27000);
PrintEntries (employees);
cout << "Firing dumb employees:\n";
employees.erase (employees.begin(), employees.begin() + 1);
PrintEntries (employees);
}
StdBvtMain (TestMultiMap)

30
extern/ustl/1.5/bvt/bvt15.std vendored Normal file
View File

@@ -0,0 +1,30 @@
As-inserted listing:
Dumb - $15000
Dave - $27000
Jim - $27000
Gail - $47000
Barbara - $47000
Mary - $47000
BigBoss - $99000
Alphabetical listing:
Dumb - $15000
Dave - $27000
Jim - $27000
Barbara - $47000
Gail - $47000
Mary - $47000
BigBoss - $99000
Employees making $47000: Barbara Gail Mary
Dave makes $27000
There are 2 low-paid employees
Firing all low-paid employees:
Dumb - $15000
Barbara - $47000
Gail - $47000
Mary - $47000
BigBoss - $99000
Firing dumb employees:
Barbara - $47000
Gail - $47000
Mary - $47000
BigBoss - $99000

86
extern/ustl/1.5/bvt/bvt16.cc vendored Normal file
View File

@@ -0,0 +1,86 @@
// This file is part of the uSTL library, an STL implementation.
//
// Copyright (c) 2005 by Mike Sharov <msharov@users.sourceforge.net>
// This file is free software, distributed under the MIT License.
#include "stdtest.h"
static void Widen (const string& str, vector<wchar_t>& result)
{
result.clear();
result.resize (str.length());
copy (str.utf8_begin(), str.utf8_end(), result.begin());
}
static void DumpWchars (const vector<wchar_t>& v)
{
foreach (vector<wchar_t>::const_iterator, i, v)
cout.format (" %u", uint32_t(*i));
}
void TestUTF8 (void)
{
cout << "Generating Unicode characters ";
vector<wchar_t> srcChars;
srcChars.resize (0xFFFF);
iota (srcChars.begin(), srcChars.end(), 0);
cout.format ("%zu - %zu\n", size_t(srcChars[0]), size_t(srcChars.back()));
cout << "Encoding to utf8.\n";
string encoded;
encoded.reserve (srcChars.size() * 4);
copy (srcChars, utf8out (back_inserter(encoded)));
static const char c_ProperEncoding[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
if (encoded.compare (encoded.begin(), encoded.begin() + VectorSize(c_ProperEncoding), VectorRange(c_ProperEncoding))) {
cout << "Encoding failed: ";
for (string::const_iterator i = encoded.begin(); i != encoded.begin() + VectorSize(c_ProperEncoding); ++ i)
cout << uint32_t(*i);
cout << endl;
}
cout << "Decoding back.\n";
vector<wchar_t> decChars;
Widen (encoded, decChars);
cout.format ("Comparing.\nsrc = %zu chars, encoded = %zu chars, decoded = %zu\n", srcChars.size(), encoded.size(), decChars.size());
size_t nDiffs = 0;
for (uoff_t i = 0; i < min (srcChars.size(), decChars.size()); ++ i) {
if (srcChars[i] != decChars[i]) {
cout.format ("%u != %u\n", uint32_t(srcChars[i]), uint32_t(decChars[i]));
++ nDiffs;
}
}
cout.format ("%zu differences between src and decoded.\n", nDiffs);
cout << "Testing wide character string::insert\n";
string ws ("1234567890", 10);
ws.insert (ws.find('1'), wchar_t(1234));
static const wchar_t c_WChars[2] = { 3456, 4567 };
ws.insert (ws.find('3'), VectorRange(c_WChars), 2);
ws.insert (ws.find('3'), wchar_t(2345));
ws.insert (ws.size(), wchar_t(5678));
cout.format ("Values[%zu]:", ws.length());
for (string::utf8_iterator j = ws.utf8_begin(); j < ws.utf8_end(); ++ j)
cout.format (" %u", uint32_t(*j));
cout << endl;
cout << "Character offsets:";
for (string::utf8_iterator k = ws.utf8_begin(); k < ws.utf8_end(); ++ k)
cout.format (" %zu", distance (ws.begin(), k.base()));
cout << endl;
cout.format ("Erasing character %zu: ", ws.length() - 1);
ws.erase (ws.wiat(ws.length() - 1), ws.end());
Widen (ws, decChars);
DumpWchars (decChars);
cout << endl;
cout << "Erasing 2 characters after '2': ";
ws.erase (ws.find('2')+1, Utf8Bytes(VectorRange(c_WChars)));
Widen (ws, decChars);
DumpWchars (decChars);
cout << endl;
}
StdBvtMain (TestUTF8)

11
extern/ustl/1.5/bvt/bvt16.std vendored Normal file
View File

@@ -0,0 +1,11 @@
Generating Unicode characters 0 - 65534
Encoding to utf8.
Decoding back.
Comparing.
src = 65535 chars, encoded = 194429 chars, decoded = 65535
0 differences between src and decoded.
Testing wide character string::insert
Values[17]: 1234 49 50 3456 4567 3456 4567 2345 51 52 53 54 55 56 57 48 5678
Character offsets: 0 2 3 4 7 10 13 16 19 20 21 22 23 24 25 26 27
Erasing character 16: 1234 49 50 3456 4567 3456 4567 2345 51 52 53 54 55 56 57 48
Erasing 2 characters after '2': 1234 49 50 3456 4567 2345 51 52 53 54 55 56 57 48

98
extern/ustl/1.5/bvt/bvt17.cc vendored Normal file
View File

@@ -0,0 +1,98 @@
// 011010011001011001011000100100
// This file is part of the uSTL library, an STL implementation.
//
// Copyright (c) 2005 by Mike Sharov <msharov@users.sourceforge.net>
// This file is free software, distributed under the MIT License.
#include "stdtest.h"
size_t SizeOfSet (const bitset<30>& v)
{
return (stream_size_of (v));
}
void TestBitset (void)
{
bitset<30> bs1;
cout.format ("bitset<%zu> bs1: capacity() = %zu, sizeof() = %zu\n", bs1.size(), bs1.capacity(), sizeof(bs1));
cout << bs1 << endl;
bs1.set();
bs1.set (6, false);
cout << bs1 << endl;
bs1.flip();
cout << bs1 << endl;
bs1.flip();
cout << bs1 << endl;
bs1.reset();
string comment; // See line 0 in this file
cin >> comment >> bs1;
cout << bs1 << endl;
cout.format ("count = %zu\n", bs1.count());
bs1.reset();
cout << bs1;
static const char tf[2][6] = { "false", "true" };
cout.format ("\nany = %s, none = %s, count = %zu\n", tf[bs1.any()], tf[bs1.none()], bs1.count());
bs1.flip();
cout << bs1;
cout.format ("\nany = %s, none = %s, count = %zu\n", tf[bs1.any()], tf[bs1.none()], bs1.count());
bs1.reset();
bs1.set (4);
bs1.set (7);
bs1.set (8);
cout << bs1;
cout.format ("\ntest(7) == %s, [9] = %s, [8] = %s", tf[bs1.test(7)], tf[bs1[9]], tf[bs1[8]]);
cout.format ("\nany = %s, none = %s, count = %zu\n", tf[bs1.any()], tf[bs1.none()], bs1.count());
cout << "~bs1 == " << ~bs1;
cout.format ("\nto_value == 0x%X\n", bs1.to_value());
bitset<70> bs2 ("0101101");
cout.format ("bitset<%zu> bs2: capacity() = %zu, sizeof() = %zu\n", bs2.size(), bs2.capacity(), sizeof(bs2));
cout << bs2;
bs2.set (34, 40, 13);
cout << "\nbs2.set(34,40,13)\n";
cout << bs2;
cout.format ("\nbs2.at(34,40) = %u\n", bs2.at(34,40));
bitset<256> bs3 (0x3030);
cout.format ("bitset<%zu> bs3: capacity() = %zu, sizeof() = %zu\n", bs3.size(), bs3.capacity(), sizeof(bs3));
cout.format ("bs3.to_value() == 0x%X\n", bs3.to_value());
bitset<30> bs4 (bs1);
if (bs1 == bs4)
cout << "bs4 == bs1\n";
bs4 = 0x50505050;
cout << "bs4 = 0x50505050: " << bs4;
bs1 = 0x30303030;
cout << "\nbs1 = 0x30303030: " << bs1;
bs4 &= bs1;
cout << "\nbs4 &= bs1; bs4 = " << bs4;
bs4 = 0x50505050;
bs4 &= bs1;
cout << "\nbs4 & bs1; bs4 = " << bs4;
bs4 = 0x50505050;
bs4 |= bs1;
cout << "\nbs4 |= bs1; bs4 = " << bs4;
bs4 = 0x50505050;
bs4 = bs4 | bs1;
cout << "\nbs4 | bs1; bs4 = " << bs4;
bs4 = 0x50505050;
bs4 ^= bs1;
cout << "\nbs4 ^= bs1; bs4 = " << bs4;
bs4 = 0x50505050;
bs4 = bs4 ^ 0x30303030;
cout << "\nbs4 ^ bs1; bs4 = " << bs4;
memblock b (stream_size_of (bs4));
ostream os (b);
os << bs4;
istream is (b);
bs4 = 0;
is >> bs4;
cout.format ("\nstream[%zu]; bs4 = ", b.size());
cout << bs4 << endl;
}
StdBvtMain (TestBitset)

33
extern/ustl/1.5/bvt/bvt17.std vendored Normal file
View File

@@ -0,0 +1,33 @@
bitset<30> bs1: capacity() = 32, sizeof() = 4
000000000000000000000000000000
111111111111111111111110111111
000000000000000000000001000000
111111111111111111111110111111
011010011001011001011000100100
count = 13
000000000000000000000000000000
any = false, none = true, count = 0
111111111111111111111111111111
any = true, none = false, count = 32
000000000000000000000110010000
test(7) == true, [9] = false, [8] = true
any = true, none = false, count = 3
~bs1 == 111111111111111111111001101111
to_value == 0x190
bitset<70> bs2: capacity() = 96, sizeof() = 12
0000000000000000000000000000000000000000000000000000000000000000101101
bs2.set(34,40,13)
0000000000000000000000000000000011010000000000000000000000000000101101
bs2.at(34,40) = 13
bitset<256> bs3: capacity() = 256, sizeof() = 32
bs3.to_value() == 0x3030
bs4 == bs1
bs4 = 0x50505050: 010000010100000101000001010000
bs1 = 0x30303030: 110000001100000011000000110000
bs4 &= bs1; bs4 = 010000000100000001000000010000
bs4 & bs1; bs4 = 010000000100000001000000010000
bs4 |= bs1; bs4 = 110000011100000111000001110000
bs4 | bs1; bs4 = 110000011100000111000001110000
bs4 ^= bs1; bs4 = 100000011000000110000001100000
bs4 ^ bs1; bs4 = 100000011000000110000001100000
stream[4]; bs4 = 100000011000000110000001100000

77
extern/ustl/1.5/bvt/bvt18.cc vendored Normal file
View File

@@ -0,0 +1,77 @@
// This file is part of the uSTL library, an STL implementation.
//
// Copyright (c) 2005 by Mike Sharov <msharov@users.sourceforge.net>
// This file is free software, distributed under the MIT License.
#include "stdtest.h"
template <size_t N, typename T>
void TestTuple (const char* ctrType)
{
cout << "================================================" << endl;
cout << "Testing " << ctrType << endl;
cout << "================================================" << endl;
assert (N <= 8);
T pt1v[8] = { 1, 2, 3, 4, 5, 6, 7, 8 };
T increment;
tuple<N,T> pt1 (pt1v);
tuple<N,T> pt2 (5, 6, 7, 8);
increment = pt1v[2];
cout << "pt1:\t\t\tsize = " << pt1.size() << ", value = " << pt1 << endl;
cout << "pt2:\t\t\t" << pt2 << endl;
iota (pt2.begin(), pt2.end(), 10);
cout << "pt2:\t\t\t" << pt2 << endl;
pt1 *= increment;
cout << "pt1 *= 3:\t\t" << pt1 << endl;
pt1 /= increment;
cout << "pt1 /= 3:\t\t" << pt1 << endl;
pt1 += increment;
cout << "pt1 += 3:\t\t" << pt1 << endl;
pt1 -= increment;
cout << "pt1 -= 3:\t\t" << pt1 << endl;
pt1 *= pt2;
cout << "pt1 *= pt2:\t\t" << pt1 << endl;
pt1 /= pt2;
cout << "pt1 /= pt2:\t\t" << pt1 << endl;
pt1 += pt2;
cout << "pt1 += pt2:\t\t" << pt1 << endl;
pt1 -= pt2;
cout << "pt1 -= pt2:\t\t" << pt1 << endl;
pt1 = pt1 * pt2;
cout << "pt1 = pt1 * pt2:\t" << pt1 << endl;
pt1 = pt1 / pt2;
cout << "pt1 = pt1 / pt2:\t" << pt1 << endl;
pt1 = pt1 + pt2;
cout << "pt1 = pt1 + pt2:\t" << pt1 << endl;
pt1 = pt1 - pt2;
cout << "pt1 = pt1 - pt2:\t" << pt1 << endl;
}
void TestIntegralTuples (void)
{
TestTuple<4,float> ("tuple<4,float>");
TestTuple<2,float> ("tuple<2,float>");
TestTuple<4,int32_t> ("tuple<4,int32_t>");
TestTuple<4,uint32_t> ("tuple<4,uint32_t>");
TestTuple<2,int32_t> ("tuple<2,int32_t>");
TestTuple<2,uint32_t> ("tuple<2,uint32_t>");
TestTuple<4,int16_t> ("tuple<4,int16_t>");
TestTuple<4,uint16_t> ("tuple<4,uint16_t>");
TestTuple<8,int8_t> ("tuple<8,int8_t>");
TestTuple<8,uint8_t> ("tuple<8,uint8_t>");
cout << "================================================" << endl;
cout << "Testing tuple<3,string>" << endl;
cout << "================================================" << endl;
tuple<3, string> strv;
strv[0] = "str0";
strv[1] = "str1";
strv[2] = "str2";
cout << "str: " << strv << endl;
}
StdBvtMain (TestIntegralTuples)

184
extern/ustl/1.5/bvt/bvt18.std vendored Normal file
View File

@@ -0,0 +1,184 @@
================================================
Testing tuple<4,float>
================================================
pt1: size = 4, value = (1.00,2.00,3.00,4.00)
pt2: (5.00,6.00,7.00,8.00)
pt2: (10.00,11.00,12.00,13.00)
pt1 *= 3: (3.00,6.00,9.00,12.00)
pt1 /= 3: (1.00,2.00,3.00,4.00)
pt1 += 3: (4.00,5.00,6.00,7.00)
pt1 -= 3: (1.00,2.00,3.00,4.00)
pt1 *= pt2: (10.00,22.00,36.00,52.00)
pt1 /= pt2: (1.00,2.00,3.00,4.00)
pt1 += pt2: (11.00,13.00,15.00,17.00)
pt1 -= pt2: (1.00,2.00,3.00,4.00)
pt1 = pt1 * pt2: (10.00,22.00,36.00,52.00)
pt1 = pt1 / pt2: (1.00,2.00,3.00,4.00)
pt1 = pt1 + pt2: (11.00,13.00,15.00,17.00)
pt1 = pt1 - pt2: (1.00,2.00,3.00,4.00)
================================================
Testing tuple<2,float>
================================================
pt1: size = 2, value = (1.00,2.00)
pt2: (5.00,6.00)
pt2: (10.00,11.00)
pt1 *= 3: (3.00,6.00)
pt1 /= 3: (1.00,2.00)
pt1 += 3: (4.00,5.00)
pt1 -= 3: (1.00,2.00)
pt1 *= pt2: (10.00,22.00)
pt1 /= pt2: (1.00,2.00)
pt1 += pt2: (11.00,13.00)
pt1 -= pt2: (1.00,2.00)
pt1 = pt1 * pt2: (10.00,22.00)
pt1 = pt1 / pt2: (1.00,2.00)
pt1 = pt1 + pt2: (11.00,13.00)
pt1 = pt1 - pt2: (1.00,2.00)
================================================
Testing tuple<4,int32_t>
================================================
pt1: size = 4, value = (1,2,3,4)
pt2: (5,6,7,8)
pt2: (10,11,12,13)
pt1 *= 3: (3,6,9,12)
pt1 /= 3: (1,2,3,4)
pt1 += 3: (4,5,6,7)
pt1 -= 3: (1,2,3,4)
pt1 *= pt2: (10,22,36,52)
pt1 /= pt2: (1,2,3,4)
pt1 += pt2: (11,13,15,17)
pt1 -= pt2: (1,2,3,4)
pt1 = pt1 * pt2: (10,22,36,52)
pt1 = pt1 / pt2: (1,2,3,4)
pt1 = pt1 + pt2: (11,13,15,17)
pt1 = pt1 - pt2: (1,2,3,4)
================================================
Testing tuple<4,uint32_t>
================================================
pt1: size = 4, value = (1,2,3,4)
pt2: (5,6,7,8)
pt2: (10,11,12,13)
pt1 *= 3: (3,6,9,12)
pt1 /= 3: (1,2,3,4)
pt1 += 3: (4,5,6,7)
pt1 -= 3: (1,2,3,4)
pt1 *= pt2: (10,22,36,52)
pt1 /= pt2: (1,2,3,4)
pt1 += pt2: (11,13,15,17)
pt1 -= pt2: (1,2,3,4)
pt1 = pt1 * pt2: (10,22,36,52)
pt1 = pt1 / pt2: (1,2,3,4)
pt1 = pt1 + pt2: (11,13,15,17)
pt1 = pt1 - pt2: (1,2,3,4)
================================================
Testing tuple<2,int32_t>
================================================
pt1: size = 2, value = (1,2)
pt2: (5,6)
pt2: (10,11)
pt1 *= 3: (3,6)
pt1 /= 3: (1,2)
pt1 += 3: (4,5)
pt1 -= 3: (1,2)
pt1 *= pt2: (10,22)
pt1 /= pt2: (1,2)
pt1 += pt2: (11,13)
pt1 -= pt2: (1,2)
pt1 = pt1 * pt2: (10,22)
pt1 = pt1 / pt2: (1,2)
pt1 = pt1 + pt2: (11,13)
pt1 = pt1 - pt2: (1,2)
================================================
Testing tuple<2,uint32_t>
================================================
pt1: size = 2, value = (1,2)
pt2: (5,6)
pt2: (10,11)
pt1 *= 3: (3,6)
pt1 /= 3: (1,2)
pt1 += 3: (4,5)
pt1 -= 3: (1,2)
pt1 *= pt2: (10,22)
pt1 /= pt2: (1,2)
pt1 += pt2: (11,13)
pt1 -= pt2: (1,2)
pt1 = pt1 * pt2: (10,22)
pt1 = pt1 / pt2: (1,2)
pt1 = pt1 + pt2: (11,13)
pt1 = pt1 - pt2: (1,2)
================================================
Testing tuple<4,int16_t>
================================================
pt1: size = 4, value = (1,2,3,4)
pt2: (5,6,7,8)
pt2: (10,11,12,13)
pt1 *= 3: (3,6,9,12)
pt1 /= 3: (1,2,3,4)
pt1 += 3: (4,5,6,7)
pt1 -= 3: (1,2,3,4)
pt1 *= pt2: (10,22,36,52)
pt1 /= pt2: (1,2,3,4)
pt1 += pt2: (11,13,15,17)
pt1 -= pt2: (1,2,3,4)
pt1 = pt1 * pt2: (10,22,36,52)
pt1 = pt1 / pt2: (1,2,3,4)
pt1 = pt1 + pt2: (11,13,15,17)
pt1 = pt1 - pt2: (1,2,3,4)
================================================
Testing tuple<4,uint16_t>
================================================
pt1: size = 4, value = (1,2,3,4)
pt2: (5,6,7,8)
pt2: (10,11,12,13)
pt1 *= 3: (3,6,9,12)
pt1 /= 3: (1,2,3,4)
pt1 += 3: (4,5,6,7)
pt1 -= 3: (1,2,3,4)
pt1 *= pt2: (10,22,36,52)
pt1 /= pt2: (1,2,3,4)
pt1 += pt2: (11,13,15,17)
pt1 -= pt2: (1,2,3,4)
pt1 = pt1 * pt2: (10,22,36,52)
pt1 = pt1 / pt2: (1,2,3,4)
pt1 = pt1 + pt2: (11,13,15,17)
pt1 = pt1 - pt2: (1,2,3,4)
================================================
Testing tuple<8,int8_t>
================================================
pt1: size = 8, value = (1,2,3,4,5,6,7,8)
pt2: (5,6,7,8,0,0,0,0)
pt2: (10,11,12,13,14,15,16,17)
pt1 *= 3: (3,6,9,12,15,18,21,24)
pt1 /= 3: (1,2,3,4,5,6,7,8)
pt1 += 3: (4,5,6,7,8,9,10,11)
pt1 -= 3: (1,2,3,4,5,6,7,8)
pt1 *= pt2: (10,22,'$','4','F','Z','p',-120)
pt1 /= pt2: (1,2,3,4,5,6,7,-7)
pt1 += pt2: (11,13,15,17,19,21,23,10)
pt1 -= pt2: (1,2,3,4,5,6,7,-7)
pt1 = pt1 * pt2: (10,22,'$','4','F','Z','p',-119)
pt1 = pt1 / pt2: (1,2,3,4,5,6,7,-7)
pt1 = pt1 + pt2: (11,13,15,17,19,21,23,10)
pt1 = pt1 - pt2: (1,2,3,4,5,6,7,-7)
================================================
Testing tuple<8,uint8_t>
================================================
pt1: size = 8, value = (1,2,3,4,5,6,7,8)
pt2: (5,6,7,8,0,0,0,0)
pt2: (10,11,12,13,14,15,16,17)
pt1 *= 3: (3,6,9,12,15,18,21,24)
pt1 /= 3: (1,2,3,4,5,6,7,8)
pt1 += 3: (4,5,6,7,8,9,10,11)
pt1 -= 3: (1,2,3,4,5,6,7,8)
pt1 *= pt2: (10,22,'$','4','F','Z','p',136)
pt1 /= pt2: (1,2,3,4,5,6,7,8)
pt1 += pt2: (11,13,15,17,19,21,23,25)
pt1 -= pt2: (1,2,3,4,5,6,7,8)
pt1 = pt1 * pt2: (10,22,'$','4','F','Z','p',136)
pt1 = pt1 / pt2: (1,2,3,4,5,6,7,8)
pt1 = pt1 + pt2: (11,13,15,17,19,21,23,25)
pt1 = pt1 - pt2: (1,2,3,4,5,6,7,8)
================================================
Testing tuple<3,string>
================================================
str: (str0,str1,str2)

33
extern/ustl/1.5/bvt/bvt19.cc vendored Normal file
View File

@@ -0,0 +1,33 @@
// This file is part of the uSTL library, an STL implementation.
//
// Copyright (c) 2005 by Mike Sharov <msharov@users.sourceforge.net>
// This file is free software, distributed under the MIT License.
#include "stdtest.h"
void TestEnumArithmetic (void)
{
enum EFruit {
apple,
orange,
plum,
peach,
pear,
nectarine,
NFruits
};
const char* fruits [NFruits + 1] = {
"apple",
"orange",
"plum",
"peach",
"pear",
"nectarine",
"invalid"
};
cout << "Testing operator+" << endl;
cout << "apple = " << fruits [apple] << endl;
cout << "peach = " << fruits [apple + 3] << endl;
}
StdBvtMain (TestEnumArithmetic)

3
extern/ustl/1.5/bvt/bvt19.std vendored Normal file
View File

@@ -0,0 +1,3 @@
Testing operator+
apple = apple
peach = peach

33
extern/ustl/1.5/bvt/bvt20.cc vendored Normal file
View File

@@ -0,0 +1,33 @@
// This file is part of the uSTL library, an STL implementation.
//
// Copyright (c) 2005 Mike Sharov <msharov@users.sourceforge.net>
// This file is free software, distributed under the MIT License.
#include "stdtest.h"
void TestStackAndQueue (void)
{
stack<int> s;
cout << "Testing stack: ";
for (size_t i = 0; i < 5; ++ i)
s.push (1 + i);
cout << "popping: ";
for (size_t j = 0; j < 5; ++ j) {
cout << s.top() << ' ';
s.pop();
}
cout << endl;
queue<int> q;
cout << "Testing queue: ";
for (size_t k = 0; k < 5; ++ k)
q.push (1 + k);
cout << "popping: ";
for (size_t l = 0; l < 5; ++ l) {
cout << q.front() << ' ';
q.pop();
}
cout << endl;
}
StdBvtMain (TestStackAndQueue)

2
extern/ustl/1.5/bvt/bvt20.std vendored Normal file
View File

@@ -0,0 +1,2 @@
Testing stack: popping: 5 4 3 2 1
Testing queue: popping: 1 2 3 4 5

108
extern/ustl/1.5/bvt/bvt21.cc vendored Normal file
View File

@@ -0,0 +1,108 @@
// This file is part of the uSTL library, an STL implementation.
//
// Copyright (c) 2005 by Mike Sharov <msharov@users.sourceforge.net>
// This file is free software, distributed under the MIT License.
#include "stdtest.h"
template <typename T>
void TestBswap (T v)
{
const T vsw (bswap(v));
#if BYTE_ORDER == LITTLE_ENDIAN
const T vbe (vsw), vle (v);
#elif BYTE_ORDER == BIG_ENDIAN
const T vbe (v), vle (vsw);
#endif
static const char ok[2][4] = { "bad", "ok" };
cout << "bswap(" << v << ") = " << vsw << endl;
cout << "le_to_native(" << v << ") = " << ok[le_to_native(vle) == v] << endl;
cout << "native_to_le(" << v << ") = " << ok[native_to_le(v) == vle] << endl;
cout << "be_to_native(" << v << ") = " << ok[be_to_native(vbe) == v] << endl;
cout << "native_to_be(" << v << ") = " << ok[native_to_be(v) == vbe] << endl;
}
void TestUtility (void)
{
cout << "DivRU(13,5) = " << DivRU(13,5) << endl;
cout << "DivRU(15,5) = " << DivRU(15,5) << endl;
cout << "DivRU(-12,5) = " << DivRU(-12,5) << endl;
cout << endl;
cout << "Align(5) = " << Align(5) << endl;
cout << "Align(5,2) = " << Align(5,2) << endl;
cout << "Align(17,7) = " << Align(17,7) << endl;
cout << "Align(14,7) = " << Align(14,7) << endl;
cout << endl;
cout << "NextPow2(0) = " << NextPow2(0) << endl;
cout << "NextPow2(1) = " << NextPow2(1) << endl;
cout << "NextPow2(4) = " << NextPow2(4) << endl;
cout << "NextPow2(3827) = " << NextPow2(3827) << endl;
cout << "NextPow2(0xFFFFFFF0) = " << NextPow2(0xFFFFFFF0) << endl;
cout << endl;
cout << "advance(42,0) = " << advance(42,0) << endl;
cout << "advance(42,3) = " << advance(42,3) << endl;
const void *cvp = (const void*) 0x1234;
void* vp = (void*) 0x4321;
cout << ios::hex;
cout << "cvp = " << cvp << endl;
cout << "vp = " << vp << endl;
cout << "advance(cvp,5) = " << advance(cvp,5) << endl;
cout << "advance(vp,4) = " << advance(vp,4) << endl;
cout << "distance(cvp,vp) = " << distance(cvp,vp) << endl;
cout << "abs_distance(vp,cvp) = " << abs_distance(vp,cvp) << endl;
cout << ios::dec << endl;
const int32_t c_Numbers[] = { 1, 2, 3, 4, 5 };
const int32_t c_Empty[] = { };
cout << "size_of_elements(3, c_Numbers) = " << size_of_elements(3, c_Numbers) << endl;
cout << "VectorSize(c_Numbers[5]) = " << VectorSize(c_Numbers) << endl;
cout << "VectorSize(c_Numbers[0]) = " << VectorSize(c_Empty) << endl;
cout << endl;
cout << "BitsInType(uint32_t) = " << BitsInType(uint32_t) << endl;
cout << "BitsInType(int16_t) = " << BitsInType(int16_t) << endl;
cout << "BitsInType(char) = " << BitsInType(char) << endl;
cout << ios::hex << endl;
cout << "BitMask(uint32_t,12) = " << BitMask(uint32_t,12) << endl;
cout << "BitMask(uint16_t,1) = " << BitMask(uint16_t,1) << endl;
cout << "BitMask(uint8_t,8) = " << BitMask(uint8_t,8) << endl;
cout << "BitMask(uint16_t,0) = " << BitMask(uint16_t,0) << endl;
cout << endl;
uint16_t packed16 = 0xCDCD;
pack_type (uint8_t(0x42), packed16);
cout << "pack_type(uint8_t, uint16_t) = " << packed16 << endl;
uint32_t packed32 = 0xCDCDCDCD;
pack_type (uint8_t(0x42), packed32);
cout << "pack_type(uint8_t, uint32_t) = " << packed32 << endl;
packed32 = 0xCDCDCDCD;
pack_type (uint16_t(0x4243), packed32);
cout << "pack_type(uint16_t, uint32_t) = " << packed32 << endl;
#if HAVE_INT64_T
uint64_t packed64 = UINT64_C(0x123456789ABCDEF0);
pack_type (uint8_t(0x42), packed64);
cout << "pack_type(uint8_t, uint64_t) = " << packed64 << endl;
packed64 = UINT64_C(0x123456789ABCDEF0);
pack_type (uint32_t(0x42434445), packed64);
cout << "pack_type(uint32_t, uint64_t) = " << packed64 << endl;
#else
cout << "No 64bit types available on this platform" << endl;
#endif
cout << endl;
TestBswap (uint16_t (0x1234));
TestBswap (uint32_t (0x12345678));
#if HAVE_INT64_T
TestBswap (uint64_t (UINT64_C(0x123456789ABCDEF0)));
#else
cout << "No 64bit types available on this platform" << endl;
#endif
cout << ios::dec << endl;
cout << "absv(12) = " << absv(12) << endl;
cout << "absv(-12) = " << absv(-12) << endl;
cout << "sign(12) = " << sign(12) << endl;
cout << "sign(-12) = " << sign(-12) << endl;
cout << "sign(0) = " << sign(0) << endl;
cout << "min(3,4) = " << min(3,4) << endl;
cout << "min(6U,1U) = " << min(6U,1U) << endl;
cout << "max(-3,-6) = " << max(-3,-6) << endl;
cout << "max(-3L,6L) = " << max(-3L,6L) << endl;
}
StdBvtMain (TestUtility)

68
extern/ustl/1.5/bvt/bvt21.std vendored Normal file
View File

@@ -0,0 +1,68 @@
DivRU(13,5) = 3
DivRU(15,5) = 3
DivRU(-12,5) = -3
Align(5) = 8
Align(5,2) = 6
Align(17,7) = 21
Align(14,7) = 14
NextPow2(0) = 1
NextPow2(1) = 2
NextPow2(4) = 4
NextPow2(3827) = 4096
NextPow2(0xFFFFFFF0) = 1
advance(42,0) = 42
advance(42,3) = 45
cvp = 1234
vp = 4321
advance(cvp,5) = 1239
advance(vp,4) = 4325
distance(cvp,vp) = 30ED
abs_distance(vp,cvp) = 30ED
size_of_elements(3, c_Numbers) = 12
VectorSize(c_Numbers[5]) = 5
VectorSize(c_Numbers[0]) = 0
BitsInType(uint32_t) = 32
BitsInType(int16_t) = 16
BitsInType(char) = 8
BitMask(uint32_t,12) = FFF
BitMask(uint16_t,1) = 1
BitMask(uint8_t,8) = FF
BitMask(uint16_t,0) = 0
pack_type(uint8_t, uint16_t) = 4242
pack_type(uint8_t, uint32_t) = 42424242
pack_type(uint16_t, uint32_t) = 42434243
pack_type(uint8_t, uint64_t) = 4242424242424242
pack_type(uint32_t, uint64_t) = 4243444542434445
bswap(1234) = 3412
le_to_native(1234) = ok
native_to_le(1234) = ok
be_to_native(1234) = ok
native_to_be(1234) = ok
bswap(12345678) = 78563412
le_to_native(12345678) = ok
native_to_le(12345678) = ok
be_to_native(12345678) = ok
native_to_be(12345678) = ok
bswap(123456789ABCDEF0) = F0DEBC9A78563412
le_to_native(123456789ABCDEF0) = ok
native_to_le(123456789ABCDEF0) = ok
be_to_native(123456789ABCDEF0) = ok
native_to_be(123456789ABCDEF0) = ok
absv(12) = 12
absv(-12) = 12
sign(12) = 1
sign(-12) = -1
sign(0) = 0
min(3,4) = 3
min(6U,1U) = 1
max(-3,-6) = -3
max(-3L,6L) = 6

71
extern/ustl/1.5/bvt/bvt22.cc vendored Normal file
View File

@@ -0,0 +1,71 @@
// This file is part of the uSTL library, an STL implementation.
//
// Copyright (c) 2005 by Mike Sharov <msharov@users.sourceforge.net>
// This file is free software, distributed under the MIT License.
#include "stdtest.h"
template <size_t NX, size_t NY, typename T>
void TestMatrix (void)
{
matrix<NX,NY,T> m1, m2;
load_identity (m1);
cout << "load_identity(m1)"
"\n m1 = " << m1;
m2 = m1;
cout << "\nm1 = m2"
"\n m2 = " << m2;
m1 += m2;
cout << "\nm1 += m2"
"\n m1 = " << m1;
m1 /= 2;
cout << "\nm1 /= 2"
"\n m1 = " << m1;
m1 = m1 * m2;
cout << "\nm1 = m1 * m2"
"\n m1 = " << m1;
m1 += 3;
cout << "\nm1 += 3"
"\n m1 = " << m1;
load_identity (m2);
m2 *= 2;
m1 = m1 * m2;
cout << "\nm1 *= I(2)";
cout << "\n m1 = " << m1;
iota (m1.begin(), m1.end(), 1);
cout << "\nm1 = iota(1)"
"\n m1 = " << m1;
cout << "\n m1 row [1] = " << m1.row(1);
cout << "\n m1 column [2] = " << m1.column(2);
m1 = m1 * m2;
cout << "\nm1 *= I(2)"
"\n m1 = " << m1;
typename matrix<NX,NY,T>::column_type v, vt;
iota (v.begin(), v.end(), 1);
cout << "\nv = iota(1)"
"\n v = " << v;
load_identity (m2);
m2 *= 2;
for (uoff_t y = 0; y < NY - 1; ++ y)
m2[NY - 1][y] = 1;
cout << "\nm2 = I(2) + T(1)"
"\n m2 = " << m2;
vt = v * m2;
cout << "\nvt = v * m2"
"\n vt = " << vt << endl;
}
void TestMatrixAlgorithms (void)
{
cout << "========================================\n"
"Testing 4x4 int matrix:\n"
"========================================\n";
TestMatrix<4,4,int>();
cout << "========================================\n"
"Testing 4x4 float matrix:\n"
"========================================\n";
cout.set_precision (1);
TestMatrix<4,4,float>();
}
StdBvtMain (TestMatrixAlgorithms)

58
extern/ustl/1.5/bvt/bvt22.std vendored Normal file
View File

@@ -0,0 +1,58 @@
========================================
Testing 4x4 int matrix:
========================================
load_identity(m1)
m1 = ((1,0,0,0)(0,1,0,0)(0,0,1,0)(0,0,0,1))
m1 = m2
m2 = ((1,0,0,0)(0,1,0,0)(0,0,1,0)(0,0,0,1))
m1 += m2
m1 = ((2,0,0,0)(0,2,0,0)(0,0,2,0)(0,0,0,2))
m1 /= 2
m1 = ((1,0,0,0)(0,1,0,0)(0,0,1,0)(0,0,0,1))
m1 = m1 * m2
m1 = ((1,0,0,0)(0,1,0,0)(0,0,1,0)(0,0,0,1))
m1 += 3
m1 = ((4,3,3,3)(3,4,3,3)(3,3,4,3)(3,3,3,4))
m1 *= I(2)
m1 = ((8,6,6,6)(6,8,6,6)(6,6,8,6)(6,6,6,8))
m1 = iota(1)
m1 = ((1,2,3,4)(5,6,7,8)(9,10,11,12)(13,14,15,16))
m1 row [1] = (5,6,7,8)
m1 column [2] = (3,7,11,15)
m1 *= I(2)
m1 = ((2,4,6,8)(10,12,14,16)(18,20,22,24)(26,28,30,32))
v = iota(1)
v = (1,2,3,4)
m2 = I(2) + T(1)
m2 = ((2,0,0,0)(0,2,0,0)(0,0,2,0)(1,1,1,2))
vt = v * m2
vt = (6,8,10,8)
========================================
Testing 4x4 float matrix:
========================================
load_identity(m1)
m1 = ((1.0,0.0,0.0,0.0)(0.0,1.0,0.0,0.0)(0.0,0.0,1.0,0.0)(0.0,0.0,0.0,1.0))
m1 = m2
m2 = ((1.0,0.0,0.0,0.0)(0.0,1.0,0.0,0.0)(0.0,0.0,1.0,0.0)(0.0,0.0,0.0,1.0))
m1 += m2
m1 = ((2.0,0.0,0.0,0.0)(0.0,2.0,0.0,0.0)(0.0,0.0,2.0,0.0)(0.0,0.0,0.0,2.0))
m1 /= 2
m1 = ((1.0,0.0,0.0,0.0)(0.0,1.0,0.0,0.0)(0.0,0.0,1.0,0.0)(0.0,0.0,0.0,1.0))
m1 = m1 * m2
m1 = ((1.0,0.0,0.0,0.0)(0.0,1.0,0.0,0.0)(0.0,0.0,1.0,0.0)(0.0,0.0,0.0,1.0))
m1 += 3
m1 = ((4.0,3.0,3.0,3.0)(3.0,4.0,3.0,3.0)(3.0,3.0,4.0,3.0)(3.0,3.0,3.0,4.0))
m1 *= I(2)
m1 = ((8.0,6.0,6.0,6.0)(6.0,8.0,6.0,6.0)(6.0,6.0,8.0,6.0)(6.0,6.0,6.0,8.0))
m1 = iota(1)
m1 = ((1.0,2.0,3.0,4.0)(5.0,6.0,7.0,8.0)(9.0,10.0,11.0,12.0)(13.0,14.0,15.0,16.0))
m1 row [1] = (5.0,6.0,7.0,8.0)
m1 column [2] = (3.0,7.0,11.0,15.0)
m1 *= I(2)
m1 = ((2.0,4.0,6.0,8.0)(10.0,12.0,14.0,16.0)(18.0,20.0,22.0,24.0)(26.0,28.0,30.0,32.0))
v = iota(1)
v = (1.0,2.0,3.0,4.0)
m2 = I(2) + T(1)
m2 = ((2.0,0.0,0.0,0.0)(0.0,2.0,0.0,0.0)(0.0,0.0,2.0,0.0)(1.0,1.0,1.0,2.0))
vt = v * m2
vt = (6.0,8.0,10.0,8.0)

121
extern/ustl/1.5/bvt/bvt23.cc vendored Normal file
View File

@@ -0,0 +1,121 @@
// This file is part of the uSTL library, an STL implementation.
//
// Copyright (c) 2005 by Mike Sharov <msharov@users.sourceforge.net>
// This file is free software, distributed under the MIT License.
#include "stdtest.h"
using namespace ustl::simd;
template <typename Ctr>
void TestBitwiseOperations (Ctr op1, Ctr op2, const Ctr op3)
{
passign (op3, op2);
pand (op1, op2);
cout << "pand(op1,op2) = " << op2 << endl;
passign (op3, op2);
por (op1, op2);
cout << "por(op1,op2) = " << op2 << endl;
passign (op3, op2);
pxor (op1, op2);
cout << "pxor(op1,op2) = " << op2 << endl;
passign (op3, op2);
pshl (op1, op2);
cout << "pshl(op1,op2) = " << op2 << endl;
passign (op3, op2);
pshr (op1, op2);
cout << "pshr(op1,op2) = " << op2 << endl;
}
template <> inline void TestBitwiseOperations (tuple<2,float>, tuple<2,float>, const tuple<2,float>) {}
template <> inline void TestBitwiseOperations (tuple<4,float>, tuple<4,float>, const tuple<4,float>) {}
template <typename Ctr>
void TestCtr (const char* ctrType)
{
cout << "================================================" << endl;
cout << "Testing " << ctrType << endl;
cout << "================================================" << endl;
Ctr op1, op2, op3;
fill (op1, 2);
iota (op2.begin(), op2.end(), 1);
cout << "op1 = " << op1 << endl;
cout << "op2 = " << op2 << endl;
passign (op2, op3);
cout << "passign(op2,op3) = " << op3 << endl;
padd (op1, op2);
cout << "padd(op1,op2) = " << op2 << endl;
psub (op1, op2);
cout << "psub(op1,op2) = " << op2 << endl;
pmul (op1, op2);
cout << "pmul(op1,op2) = " << op2 << endl;
pdiv (op1, op2);
cout << "pdiv(op1,op2) = " << op2 << endl;
TestBitwiseOperations (op1, op2, op3);
passign (op3, op2);
reverse (op2);
pmin (op3, op2);
cout << "pmin(op3,op2) = " << op2 << endl;
passign (op3, op2);
reverse (op2);
pmax (op3, op2);
cout << "pmax(op3,op2) = " << op2 << endl;
passign (op3, op2);
reverse (op2);
reset_mmx();
pavg (op3, op2);
cout << "pavg(op3,op2) = " << op2 << endl;
reset_mmx();
}
template <typename SrcCtr, typename DstCtr, typename Operation>
void TestConversion (const char* ctrType)
{
cout << "================================================" << endl;
cout << "Testing " << ctrType << endl;
cout << "================================================" << endl;
SrcCtr src;
DstCtr dst;
typedef typename SrcCtr::value_type srcval_t;
iota (src.begin(), src.end(), srcval_t(-1.4));
pconvert (src, dst, Operation());
cout << src << " -> " << dst << endl;
iota (src.begin(), src.end(), srcval_t(-1.5));
pconvert (src, dst, Operation());
cout << src << " -> " << dst << endl;
iota (src.begin(), src.end(), srcval_t(-1.7));
pconvert (src, dst, Operation());
cout << src << " -> " << dst << endl;
}
void TestSimdAlgorithms (void)
{
TestCtr<tuple<8,uint8_t> >("uint8_t[8]");
TestCtr<tuple<8,int8_t> >("int8_t[8]");
TestCtr<tuple<4,uint16_t> >("uint16_t[4]");
TestCtr<tuple<4,int16_t> >("int16_t[4]");
TestCtr<tuple<2,uint32_t> >("uint32_t[2]");
TestCtr<tuple<2,int32_t> >("int32_t[2]");
#if HAVE_INT64_T
TestCtr<tuple<1,uint64_t> >("uint64_t[1]");
TestCtr<tuple<1,int64_t> >("int64_t[1]");
#else
cout << "No 64bit types available on this platform" << endl;
#endif
TestCtr<tuple<2,float> >("float[2]");
TestCtr<tuple<4,float> >("float[4]");
TestCtr<tuple<7,uint32_t> >("uint32_t[7]");
#if HAVE_MATH_H
#define CVT_TEST(size,src,dest,op) \
TestConversion<tuple<size,src>, tuple<size,dest>, op<src,dest> > (#op " " #src " -> " #dest)
CVT_TEST(4,int32_t,float,fround);
CVT_TEST(4,int32_t,double,fround);
CVT_TEST(4,float,int32_t,fround);
CVT_TEST(4,double,int32_t,fround);
CVT_TEST(4,float,int32_t,fcast);
#else
cout << "CAN'T TEST: math.h functions are not available on this platform." << endl;
#endif
}
StdBvtMain (TestSimdAlgorithms)

218
extern/ustl/1.5/bvt/bvt23.std vendored Normal file
View File

@@ -0,0 +1,218 @@
================================================
Testing uint8_t[8]
================================================
op1 = (2,2,2,2,2,2,2,2)
op2 = (1,2,3,4,5,6,7,8)
passign(op2,op3) = (1,2,3,4,5,6,7,8)
padd(op1,op2) = (3,4,5,6,7,8,9,10)
psub(op1,op2) = (1,2,3,4,5,6,7,8)
pmul(op1,op2) = (2,4,6,8,10,12,14,16)
pdiv(op1,op2) = (1,2,3,4,5,6,7,8)
pand(op1,op2) = (0,2,2,0,0,2,2,0)
por(op1,op2) = (3,2,3,6,7,6,7,10)
pxor(op1,op2) = (3,0,1,6,7,4,5,10)
pshl(op1,op2) = (4,8,12,16,20,24,28,' ')
pshr(op1,op2) = (0,0,0,1,1,1,1,2)
pmin(op3,op2) = (1,2,3,4,4,3,2,1)
pmax(op3,op2) = (8,7,6,5,5,6,7,8)
pavg(op3,op2) = (5,5,5,5,5,5,5,5)
================================================
Testing int8_t[8]
================================================
op1 = (2,2,2,2,2,2,2,2)
op2 = (1,2,3,4,5,6,7,8)
passign(op2,op3) = (1,2,3,4,5,6,7,8)
padd(op1,op2) = (3,4,5,6,7,8,9,10)
psub(op1,op2) = (1,2,3,4,5,6,7,8)
pmul(op1,op2) = (2,4,6,8,10,12,14,16)
pdiv(op1,op2) = (1,2,3,4,5,6,7,8)
pand(op1,op2) = (0,2,2,0,0,2,2,0)
por(op1,op2) = (3,2,3,6,7,6,7,10)
pxor(op1,op2) = (3,0,1,6,7,4,5,10)
pshl(op1,op2) = (4,8,12,16,20,24,28,' ')
pshr(op1,op2) = (0,0,0,1,1,1,1,2)
pmin(op3,op2) = (1,2,3,4,4,3,2,1)
pmax(op3,op2) = (8,7,6,5,5,6,7,8)
pavg(op3,op2) = (5,5,5,5,5,5,5,5)
================================================
Testing uint16_t[4]
================================================
op1 = (2,2,2,2)
op2 = (1,2,3,4)
passign(op2,op3) = (1,2,3,4)
padd(op1,op2) = (3,4,5,6)
psub(op1,op2) = (1,2,3,4)
pmul(op1,op2) = (2,4,6,8)
pdiv(op1,op2) = (1,2,3,4)
pand(op1,op2) = (0,2,2,0)
por(op1,op2) = (3,2,3,6)
pxor(op1,op2) = (3,0,1,6)
pshl(op1,op2) = (4,8,12,16)
pshr(op1,op2) = (0,0,0,1)
pmin(op3,op2) = (1,2,2,1)
pmax(op3,op2) = (4,3,3,4)
pavg(op3,op2) = (3,3,3,3)
================================================
Testing int16_t[4]
================================================
op1 = (2,2,2,2)
op2 = (1,2,3,4)
passign(op2,op3) = (1,2,3,4)
padd(op1,op2) = (3,4,5,6)
psub(op1,op2) = (1,2,3,4)
pmul(op1,op2) = (2,4,6,8)
pdiv(op1,op2) = (1,2,3,4)
pand(op1,op2) = (0,2,2,0)
por(op1,op2) = (3,2,3,6)
pxor(op1,op2) = (3,0,1,6)
pshl(op1,op2) = (4,8,12,16)
pshr(op1,op2) = (0,0,0,1)
pmin(op3,op2) = (1,2,2,1)
pmax(op3,op2) = (4,3,3,4)
pavg(op3,op2) = (3,3,3,3)
================================================
Testing uint32_t[2]
================================================
op1 = (2,2)
op2 = (1,2)
passign(op2,op3) = (1,2)
padd(op1,op2) = (3,4)
psub(op1,op2) = (1,2)
pmul(op1,op2) = (2,4)
pdiv(op1,op2) = (1,2)
pand(op1,op2) = (0,2)
por(op1,op2) = (3,2)
pxor(op1,op2) = (3,0)
pshl(op1,op2) = (4,8)
pshr(op1,op2) = (0,0)
pmin(op3,op2) = (1,1)
pmax(op3,op2) = (2,2)
pavg(op3,op2) = (2,2)
================================================
Testing int32_t[2]
================================================
op1 = (2,2)
op2 = (1,2)
passign(op2,op3) = (1,2)
padd(op1,op2) = (3,4)
psub(op1,op2) = (1,2)
pmul(op1,op2) = (2,4)
pdiv(op1,op2) = (1,2)
pand(op1,op2) = (0,2)
por(op1,op2) = (3,2)
pxor(op1,op2) = (3,0)
pshl(op1,op2) = (4,8)
pshr(op1,op2) = (0,0)
pmin(op3,op2) = (1,1)
pmax(op3,op2) = (2,2)
pavg(op3,op2) = (2,2)
================================================
Testing uint64_t[1]
================================================
op1 = (2)
op2 = (1)
passign(op2,op3) = (1)
padd(op1,op2) = (3)
psub(op1,op2) = (1)
pmul(op1,op2) = (2)
pdiv(op1,op2) = (1)
pand(op1,op2) = (0)
por(op1,op2) = (3)
pxor(op1,op2) = (3)
pshl(op1,op2) = (4)
pshr(op1,op2) = (0)
pmin(op3,op2) = (1)
pmax(op3,op2) = (1)
pavg(op3,op2) = (1)
================================================
Testing int64_t[1]
================================================
op1 = (2)
op2 = (1)
passign(op2,op3) = (1)
padd(op1,op2) = (3)
psub(op1,op2) = (1)
pmul(op1,op2) = (2)
pdiv(op1,op2) = (1)
pand(op1,op2) = (0)
por(op1,op2) = (3)
pxor(op1,op2) = (3)
pshl(op1,op2) = (4)
pshr(op1,op2) = (0)
pmin(op3,op2) = (1)
pmax(op3,op2) = (1)
pavg(op3,op2) = (1)
================================================
Testing float[2]
================================================
op1 = (2.00,2.00)
op2 = (1.00,2.00)
passign(op2,op3) = (1.00,2.00)
padd(op1,op2) = (3.00,4.00)
psub(op1,op2) = (1.00,2.00)
pmul(op1,op2) = (2.00,4.00)
pdiv(op1,op2) = (1.00,2.00)
pmin(op3,op2) = (1.00,1.00)
pmax(op3,op2) = (2.00,2.00)
pavg(op3,op2) = (1.50,1.50)
================================================
Testing float[4]
================================================
op1 = (2.00,2.00,2.00,2.00)
op2 = (1.00,2.00,3.00,4.00)
passign(op2,op3) = (1.00,2.00,3.00,4.00)
padd(op1,op2) = (3.00,4.00,5.00,6.00)
psub(op1,op2) = (1.00,2.00,3.00,4.00)
pmul(op1,op2) = (2.00,4.00,6.00,8.00)
pdiv(op1,op2) = (1.00,2.00,3.00,4.00)
pmin(op3,op2) = (1.00,2.00,2.00,1.00)
pmax(op3,op2) = (4.00,3.00,3.00,4.00)
pavg(op3,op2) = (2.50,2.50,2.50,2.50)
================================================
Testing uint32_t[7]
================================================
op1 = (2,2,2,2,2,2,2)
op2 = (1,2,3,4,5,6,7)
passign(op2,op3) = (1,2,3,4,5,6,7)
padd(op1,op2) = (3,4,5,6,7,8,9)
psub(op1,op2) = (1,2,3,4,5,6,7)
pmul(op1,op2) = (2,4,6,8,10,12,14)
pdiv(op1,op2) = (1,2,3,4,5,6,7)
pand(op1,op2) = (0,2,2,0,0,2,2)
por(op1,op2) = (3,2,3,6,7,6,7)
pxor(op1,op2) = (3,0,1,6,7,4,5)
pshl(op1,op2) = (4,8,12,16,20,24,28)
pshr(op1,op2) = (0,0,0,1,1,1,1)
pmin(op3,op2) = (1,2,3,4,3,2,1)
pmax(op3,op2) = (7,6,5,4,5,6,7)
pavg(op3,op2) = (4,4,4,4,4,4,4)
================================================
Testing fround int32_t -> float
================================================
(-1,0,1,2) -> (-1.00,0.00,1.00,2.00)
(-1,0,1,2) -> (-1.00,0.00,1.00,2.00)
(-1,0,1,2) -> (-1.00,0.00,1.00,2.00)
================================================
Testing fround int32_t -> double
================================================
(-1,0,1,2) -> (-1.00,0.00,1.00,2.00)
(-1,0,1,2) -> (-1.00,0.00,1.00,2.00)
(-1,0,1,2) -> (-1.00,0.00,1.00,2.00)
================================================
Testing fround float -> int32_t
================================================
(-1.40,-0.40,0.60,1.60) -> (-1,0,1,2)
(-1.50,-0.50,0.50,1.50) -> (-2,0,0,2)
(-1.70,-0.70,0.30,1.30) -> (-2,-1,0,1)
================================================
Testing fround double -> int32_t
================================================
(-1.40,-0.40,0.60,1.60) -> (-1,0,1,2)
(-1.50,-0.50,0.50,1.50) -> (-2,0,0,2)
(-1.70,-0.70,0.30,1.30) -> (-2,-1,0,1)
================================================
Testing fcast float -> int32_t
================================================
(-1.40,-0.40,0.60,1.60) -> (-1,0,0,1)
(-1.50,-0.50,0.50,1.50) -> (-1,0,0,1)
(-1.70,-0.70,0.30,1.30) -> (-1,0,0,1)

100
extern/ustl/1.5/bvt/bvt24.cc vendored Normal file
View File

@@ -0,0 +1,100 @@
// This file is part of the uSTL library, an STL implementation.
//
// Copyright (c) 2005 by Mike Sharov <msharov@users.sourceforge.net>
// This file is free software, distributed under the MIT License.
#include "stdtest.h"
static void HeapSize (size_t nElements, size_t& layerWidth, size_t& nLayers)
{
layerWidth = 0;
nLayers = 0;
for (size_t fts = 0; nElements > fts; fts += layerWidth) {
layerWidth *= 2;
if (!layerWidth)
++ layerWidth;
++ nLayers;
}
}
static void PrintSpace (size_t n)
{
for (uoff_t s = 0; s < n; ++ s)
cout << ' ';
}
static void PrintHeap (const vector<int>& v)
{
size_t maxWidth, nLayers;
HeapSize (v.size(), maxWidth, nLayers);
vector<int>::const_iterator src (v.begin());
cout << ios::width(3);
maxWidth *= 3;
for (uoff_t i = 0; i < nLayers; ++ i) {
const size_t w = 1 << i;
const size_t spacing = max (0, int(maxWidth / w) - 3);
PrintSpace (spacing / 2);
for (uoff_t j = 0; j < w && src != v.end(); ++ j) {
cout << *src++;
if (j < w - 1 && src != v.end() - 1)
PrintSpace (spacing);
}
cout << endl;
}
}
void TestHeapOperations (void)
{
static const int c_Values [31] = { // 31 values make a full 4-layer tree
93, 92, 90, 86, 83, 86, 77, 40, 72, 36, 68, 82, 62, 67, 63, 15,
26, 26, 49, 21, 11, 62, 67, 27, 29, 30, 35, 23, 59, 35, 29
};
vector<int> v;
v.reserve (VectorSize(c_Values));
for (uoff_t i = 0; i < VectorSize(c_Values); ++ i) {
v.push_back (c_Values[i]);
push_heap (v.begin(), v.end());
cout << "------------------------------------------------\n";
if (!is_heap (v.begin(), v.end()))
cout << "Is NOT a heap\n";
PrintHeap (v);
}
cout << "------------------------------------------------\n";
cout << "make_heap on the full range:\n";
v.resize (VectorSize (c_Values));
copy (VectorRange(c_Values), v.begin());
make_heap (v.begin(), v.end());
PrintHeap (v);
if (!is_heap (v.begin(), v.end()))
cout << "Is NOT a heap\n";
cout << "------------------------------------------------\n";
cout << "pop_heap:\n";
pop_heap (v.begin(), v.end());
v.pop_back();
PrintHeap (v);
if (!is_heap (v.begin(), v.end()))
cout << "Is NOT a heap\n";
cout << "------------------------------------------------\n";
cout << "sort_heap:\n";
v.resize (VectorSize (c_Values));
copy (VectorRange(c_Values), v.begin());
make_heap (v.begin(), v.end());
sort_heap (v.begin(), v.end());
foreach (vector<int>::const_iterator, i, v)
cout << *i;
cout << endl;
cout << "------------------------------------------------\n";
cout << "priority_queue push and pop:\n";
priority_queue<int> q;
for (uoff_t i = 0; i < VectorSize(c_Values); ++ i)
q.push (c_Values[i]);
while (!q.empty()) {
cout << q.top();
q.pop();
}
cout << endl;
}
StdBvtMain (TestHeapOperations)

180
extern/ustl/1.5/bvt/bvt24.std vendored Normal file
View File

@@ -0,0 +1,180 @@
------------------------------------------------
93
------------------------------------------------
93
92
------------------------------------------------
93
92 90
------------------------------------------------
93
92 90
86
------------------------------------------------
93
92 90
86 83
------------------------------------------------
93
92 90
86 83 86
------------------------------------------------
93
92 90
86 83 86 77
------------------------------------------------
93
92 90
86 83 86 77
40
------------------------------------------------
93
92 90
86 83 86 77
40 72
------------------------------------------------
93
92 90
86 83 86 77
40 72 36
------------------------------------------------
93
92 90
86 83 86 77
40 72 36 68
------------------------------------------------
93
92 90
86 83 86 77
40 72 36 68 82
------------------------------------------------
93
92 90
86 83 86 77
40 72 36 68 82 62
------------------------------------------------
93
92 90
86 83 86 77
40 72 36 68 82 62 67
------------------------------------------------
93
92 90
86 83 86 77
40 72 36 68 82 62 67 63
------------------------------------------------
93
92 90
86 83 86 77
40 72 36 68 82 62 67 63
15
------------------------------------------------
93
92 90
86 83 86 77
40 72 36 68 82 62 67 63
15 26
------------------------------------------------
93
92 90
86 83 86 77
40 72 36 68 82 62 67 63
15 26 26
------------------------------------------------
93
92 90
86 83 86 77
40 72 36 68 82 62 67 63
15 26 26 49
------------------------------------------------
93
92 90
86 83 86 77
40 72 36 68 82 62 67 63
15 26 26 49 21
------------------------------------------------
93
92 90
86 83 86 77
40 72 36 68 82 62 67 63
15 26 26 49 21 11
------------------------------------------------
93
92 90
86 83 86 77
40 72 36 68 82 62 67 63
15 26 26 49 21 11 62
------------------------------------------------
93
92 90
86 83 86 77
40 72 36 68 82 62 67 63
15 26 26 49 21 11 62 67
------------------------------------------------
93
92 90
86 83 86 77
40 72 36 68 82 62 67 63
15 26 26 49 21 11 62 67 27
------------------------------------------------
93
92 90
86 83 86 77
40 72 36 68 82 62 67 63
15 26 26 49 21 11 62 67 27 29
------------------------------------------------
93
92 90
86 83 86 77
40 72 36 68 82 62 67 63
15 26 26 49 21 11 62 67 27 29 30
------------------------------------------------
93
92 90
86 83 86 77
40 72 36 68 82 62 67 63
15 26 26 49 21 11 62 67 27 29 30 35
------------------------------------------------
93
92 90
86 83 86 77
40 72 36 68 82 62 67 63
15 26 26 49 21 11 62 67 27 29 30 35 23
------------------------------------------------
93
92 90
86 83 86 77
40 72 36 68 82 62 67 63
15 26 26 49 21 11 62 67 27 29 30 35 23 59
------------------------------------------------
93
92 90
86 83 86 77
40 72 36 68 82 62 67 63
15 26 26 49 21 11 62 67 27 29 30 35 23 59 35
------------------------------------------------
93
92 90
86 83 86 77
40 72 36 68 82 62 67 63
15 26 26 49 21 11 62 67 27 29 30 35 23 59 35 29
------------------------------------------------
make_heap on the full range:
93
92 90
86 83 86 77
40 72 36 68 82 62 67 63
15 26 26 49 21 11 62 67 27 29 30 35 23 59 35 29
------------------------------------------------
pop_heap:
92
86 90
72 83 86 77
40 49 36 68 82 62 67 63
15 26 26 29 21 11 62 67 27 29 30 35 23 59 35
------------------------------------------------
sort_heap:
11 15 21 23 26 26 27 29 29 30 35 35 36 40 49 59 62 62 63 67 67 68 72 77 82 83 86 86 90 92 93
------------------------------------------------
priority_queue push and pop:
93 92 90 86 86 83 82 77 72 68 67 67 63 62 62 59 49 40 36 35 35 30 29 29 27 26 26 23 21 15 11

22
extern/ustl/1.5/bvt/bvt25.cc vendored Normal file
View File

@@ -0,0 +1,22 @@
// This file is part of the uSTL library, an STL implementation.
//
// Copyright (c) 2005 by Mike Sharov <msharov@users.sourceforge.net>
// This file is free software, distributed under the MIT License.
#include "stdtest.h"
void TestFStream (void)
{
fstream fs ("bvt/bvt25.std", ios::in | ios::nocreate);
if (!fs && !(fs.open("bvt25.std", ios::in | ios::nocreate),fs))
cout << "Failed to open bvt25.std" << endl;
string buf;
buf.resize (fs.size());
if (buf.size() != 71)
cout << "fstream.size() returned " << buf.size() << endl;
fs.read (buf.begin(), buf.size());
cout << buf;
fs.close();
}
StdBvtMain (TestFStream)

5
extern/ustl/1.5/bvt/bvt25.std vendored Normal file
View File

@@ -0,0 +1,5 @@
Hello world!
123 456 789
two words
and three words
and even four words

19
extern/ustl/1.5/bvt/bvt26.cc vendored Normal file
View File

@@ -0,0 +1,19 @@
// This file is part of the uSTL library, an STL implementation.
//
// Copyright (c) 2005 by Mike Sharov <msharov@users.sourceforge.net>
// This file is free software, distributed under the MIT License.
#include "stdtest.h"
void TestMacros (void)
{
#define VARNAME(n) LARG_NUMBER(v,n)
#define VARDECL(n) VARNAME(n) = n
int COMMA_LIST (9, VARDECL);
cout << LIST(9, VARNAME, <<) << endl;
#define TO_STRING(n) #n
#define PRINT_N(n) REPEAT(n, TO_STRING) "\n"
cout << LIST(9, PRINT_N, <<);
}
StdBvtMain (TestMacros)

10
extern/ustl/1.5/bvt/bvt26.std vendored Normal file
View File

@@ -0,0 +1,10 @@
123456789
1
12
123
1234
12345
123456
1234567
12345678
123456789

57
extern/ustl/1.5/bvt/bvt27.cc vendored Normal file
View File

@@ -0,0 +1,57 @@
// This file is part of the uSTL library, an STL implementation.
//
// Copyright (c) 2005 by Mike Sharov <msharov@users.sourceforge.net>
// This file is free software, distributed under the MIT License.
#include "stdtest.h"
using namespace tm;
void Print (int v)
{ cout.format ("PrintInt %d\n", v); }
void Print (short v)
{ cout.format ("PrintShort %d\n", v); }
void Print (float v)
{ cout.format ("PrintFloat %.2f\n", v); }
class Base { };
class Derived : public Base { };
void TestTypelists (void)
{
cout << "----------------------------------------------------------------------\n"
" Testing functionality from typet.h\n"
"----------------------------------------------------------------------\n";
NullType nullType;
cout.format ("sizeof(NullType) = %zu\n", sizeof(nullType));
cout.format ("Int2Type(42)::value = %d\n", Int2Type<42>::value);
Type2Type<int>::OriginalType t2tiv = 56;
cout.format ("Type2Type type value = %d\n", t2tiv);
cout << "int == int is " << bool(IsSameType<int, int>::value) << endl;
cout << "float == int is " << bool(IsSameType<float, int>::value) << endl;
Print (Select<Conversion<long,int>::exists2Way, int, float>::Result(567));
cout << "Base is SuperSubclass from Derived is " << bool(SuperSubclass<Base,Derived>::value) << endl;
cout << "Base is SuperSubclass from Base is " << bool(SuperSubclass<Base,Base>::value) << endl;
cout << "Base is SuperSubclassStrict from Derived is " << bool(SuperSubclassStrict<Base,Derived>::value) << endl;
cout << "Base is SuperSubclassStrict from Base is " << bool(SuperSubclassStrict<Base,Base>::value) << endl;
cout << "\n----------------------------------------------------------------------\n"
" Testing functionality from typelist.h\n"
"----------------------------------------------------------------------\n";
typedef tl::Seq<char, int, short, long>::Type IntTypesList;
typedef tl::Seq<float, double>::Type FloatTypesList;
cout.format ("Length of IntTypesList is %d\n", tl::Length<IntTypesList>::value);
Print (tl::TypeAt<IntTypesList, 2>::Result(1234));
Print (tl::TypeAtNonStrict<FloatTypesList, 0, int>::Result(1235));
Print (tl::TypeAtNonStrict<FloatTypesList, 2, short>::Result(1236));
typedef tl::Append<IntTypesList, FloatTypesList>::Result AllTypesList;
cout.format ("Index of double in AllTypesList is %d\n", tl::IndexOf<AllTypesList,double>::value);
typedef tl::Erase<AllTypesList, float>::Result NoFloatList;
cout.format ("Index of float in NoFloatList is %d\n", tl::IndexOf<NoFloatList,float>::value);
cout.format ("Index of double in NoFloatList is %d\n", tl::IndexOf<NoFloatList,double>::value);
typedef tl::Reverse<AllTypesList>::Result ReversedList;
cout.format ("Index of double in ReversedList is %d\n", tl::IndexOf<ReversedList,double>::value);
}
StdBvtMain (TestTypelists)

25
extern/ustl/1.5/bvt/bvt27.std vendored Normal file
View File

@@ -0,0 +1,25 @@
----------------------------------------------------------------------
Testing functionality from typet.h
----------------------------------------------------------------------
sizeof(NullType) = 1
Int2Type(42)::value = 42
Type2Type type value = 56
int == int is true
float == int is false
PrintInt 567
Base is SuperSubclass from Derived is true
Base is SuperSubclass from Base is true
Base is SuperSubclassStrict from Derived is true
Base is SuperSubclassStrict from Base is false
----------------------------------------------------------------------
Testing functionality from typelist.h
----------------------------------------------------------------------
Length of IntTypesList is 4
PrintShort 1234
PrintFloat 1235.00
PrintShort 1236
Index of double in AllTypesList is 5
Index of float in NoFloatList is -1
Index of double in NoFloatList is 4
Index of double in ReversedList is 0

72
extern/ustl/1.5/bvt/stdtest.cc vendored Normal file
View File

@@ -0,0 +1,72 @@
// This file is part of the uSTL library, an STL implementation.
//
// Copyright (c) 2005 by Mike Sharov <msharov@users.sourceforge.net>
// This file is free software, distributed under the MIT License.
#define _GNU_SOURCE 1
#include "stdtest.h"
#include <signal.h>
#include <unistd.h>
/// Called when a signal is received.
static void OnSignal (int sig)
{
static int doubleSignal = false;
if (!TestAndSet (&doubleSignal))
abort();
alarm (1);
cout.flush();
#if HAVE_STRSIGNAL
cerr.format ("Fatal error: %s received.\n", strsignal(sig));
#else
cerr.format ("Fatal error: system signal %d received.\n", sig);
#endif
cerr.flush();
exit (sig);
}
/// Called by the framework on unrecoverable exception handling errors.
static void Terminate (void)
{
assert (!"Unrecoverable exception handling error detected.");
raise (SIGABRT);
exit (EXIT_FAILURE);
}
/// Called when an exception violates a throw specification.
static void OnUnexpected (void)
{
cerr << "Fatal internal error: unexpected exception caught.\n";
Terminate();
}
/// Installs OnSignal as handler for signals.
static void InstallCleanupHandlers (void)
{
static const uint8_t c_Signals[] = {
SIGINT, SIGQUIT, SIGILL, SIGTRAP, SIGABRT,
SIGIOT, SIGBUS, SIGFPE, SIGSEGV, SIGTERM,
SIGIO, SIGCHLD
};
for (uoff_t i = 0; i < VectorSize(c_Signals); ++i)
signal (c_Signals[i], OnSignal);
std::set_terminate (Terminate);
std::set_unexpected (OnUnexpected);
}
int StdTestHarness (stdtestfunc_t testFunction)
{
InstallCleanupHandlers();
int rv = EXIT_FAILURE;
try {
(*testFunction)();
rv = EXIT_SUCCESS;
} catch (ustl::exception& e) {
cout.flush();
cerr << "Error: " << e << endl;
} catch (...) {
cout.flush();
cerr << "Unexpected error." << endl;
}
return (rv);
}

18
extern/ustl/1.5/bvt/stdtest.h vendored Normal file
View File

@@ -0,0 +1,18 @@
// This file is part of the uSTL library, an STL implementation.
//
// Copyright (c) 2005 by Mike Sharov <msharov@users.sourceforge.net>
// This file is free software, distributed under the MIT License.
#ifndef STDTEST_H_4980DC406FEEBBDF2235E42C4EFF1A4E
#define STDTEST_H_4980DC406FEEBBDF2235E42C4EFF1A4E
#include <ustl.h>
using namespace ustl;
typedef void (*stdtestfunc_t)(void);
int StdTestHarness (stdtestfunc_t testFunction);
#define StdBvtMain(function) int main (void) { return (StdTestHarness (&function)); }
#endif