Skip to content

Commit

Permalink
add allocator
Browse files Browse the repository at this point in the history
  • Loading branch information
U-Jrong-PC\Jrong committed Jan 17, 2015
1 parent 8b53347 commit 3dc0d35
Show file tree
Hide file tree
Showing 15 changed files with 59 additions and 9 deletions.
12 changes: 12 additions & 0 deletions build/Debug/sb-stl.Build.CppClean.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
d:\projects\sb-stl\build\debug\vc120.pdb
d:\projects\sb-stl\build\debug\vc120.idb
d:\projects\sb-stl\build\debug\test.obj
d:\projects\sb-stl\build\debug\sb-stl.ilk
d:\projects\sb-stl\build\debug\sb-stl.exe
d:\projects\sb-stl\build\debug\sb-stl.pdb
d:\projects\sb-stl\build\debug\sb-stl.tlog\cl.command.1.tlog
d:\projects\sb-stl\build\debug\sb-stl.tlog\cl.read.1.tlog
d:\projects\sb-stl\build\debug\sb-stl.tlog\cl.write.1.tlog
d:\projects\sb-stl\build\debug\sb-stl.tlog\link.command.1.tlog
d:\projects\sb-stl\build\debug\sb-stl.tlog\link.read.1.tlog
d:\projects\sb-stl\build\debug\sb-stl.tlog\link.write.1.tlog
Binary file modified build/Debug/sb-stl.exe
Binary file not shown.
Binary file modified build/Debug/sb-stl.ilk
Binary file not shown.
Binary file modified build/Debug/sb-stl.pdb
Binary file not shown.
Binary file modified build/Debug/sb-stl.tlog/CL.read.1.tlog
Binary file not shown.
Binary file modified build/Debug/test.obj
Binary file not shown.
Binary file modified build/Debug/vc120.idb
Binary file not shown.
Binary file modified build/Debug/vc120.pdb
Binary file not shown.
Binary file modified build/sb-stl.v12.suo
Binary file not shown.
1 change: 1 addition & 0 deletions build/sb-stl.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="..\sb_algo.h" />
<ClInclude Include="..\sb_alloc.h" />
<ClInclude Include="..\sb_config.h" />
<ClInclude Include="..\sb_construct.h" />
<ClInclude Include="..\sb_defalloc.h" />
Expand Down
1 change: 1 addition & 0 deletions build/sb-stl.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<ClInclude Include="..\sb_construct.h" />
<ClInclude Include="..\sb_memory.h" />
<ClInclude Include="..\sb_algo.h" />
<ClInclude Include="..\sb_alloc.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\test.cpp" />
Expand Down
23 changes: 23 additions & 0 deletions sb_alloc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@


#ifndef _SB_ALLOC_H_
#define _SB_ALLOC_H_

#include "sb_types.h"

namespace sb {

template <class Type>
class allocator {
typedef Type value_type;
typedef Type* pointer;
typedef const Type* const_pointer;
typedef Type& reference;
typedef const Type& const_reference;
typedef size_t size_type;
typedef ptrdiff_t difference_type;

};
};

#endif
20 changes: 15 additions & 5 deletions sb_construct.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,32 @@

namespace sb {

template <class Type>
inline void construct(Type *pointer)
{
new (pointer)Type();
}

template <class Type, class Value>
inline void construct(Type *pointer, const Value& value)
{
new (pointer) Type(value);
}

template <class Type>
inline void construct(Type *pointer)
inline void destroy(Type *pointer)
{
pointer->~Type();
}

inline void destroy(char*, char*)
{
new (pointer) Type();

}

template <class Type>
inline void destroy(Type *pointer)
inline void destroy(wchar_t*, wchar_t*)
{
pointer->~Type();

}
}

Expand Down
4 changes: 2 additions & 2 deletions sb_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#ifndef _SB_TYPES_H_
#define _SB_TYPES_H_

#include <cstdint>
#include <cstddef>
#include <stdint.h>
#include <stddef.h>

#endif
7 changes: 5 additions & 2 deletions test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ int main(void)
v.push_back(i);
}

auto i = sb::find(v.begin(), v.end(), 5);
cout << *i << endl;
auto it = v.begin();
std::advance(it, 5);

std::cout << *it << std::endl;

return 0;
}

0 comments on commit 3dc0d35

Please sign in to comment.