Skip to content

Commit

Permalink
--ignore the MSVC database linker files
Browse files Browse the repository at this point in the history
--added push variant for rvalue references
--added debug build script for MSVC
--split test to lvalue and rvalue variants
  • Loading branch information
selassje committed Jul 25, 2019
1 parent 63d4b64 commit abf84c8
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 14 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
*.filters
*.vcxproj
*.sln
*.dll
*.dll
*.ilk
3 changes: 3 additions & 0 deletions build/msvc2019/buildDebug.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
conan install -s build_type=Debug -s compiler.toolset=v141 ../..
cmake ../..
cmake --build . --config Debug
File renamed without changes.
23 changes: 21 additions & 2 deletions src/lfQueue/lfQueue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace lfQueue
public:
std::size_t size() const {return m_Size;}
void push(const T &t) noexcept;
void push(const T &&t) noexcept;
void pop() noexcept;
const T& back() const noexcept;
const T& front() const noexcept;
Expand All @@ -24,16 +25,19 @@ namespace lfQueue
pNode next = nullptr;
node* previous = nullptr;
node(const T &t): data(t) {}
node() = default;
};

void push_internal(pNode& newNode) noexcept;


pNode m_Tail = nullptr;
pNode m_Head = nullptr;
};

template<typename T>
void lfQueue<T>::push(const T &t) noexcept
void lfQueue<T>::push_internal(pNode &pNewNode) noexcept
{
pNode pNewNode = std::make_unique<node>(t);
if (m_Size != 0)
{
pNewNode->next = std::unique_ptr<node>(m_Tail.get());
Expand All @@ -47,6 +51,21 @@ namespace lfQueue
m_Tail = std::move(pNewNode);
++m_Size;
}

template<typename T>
void lfQueue<T>::push(const T& t) noexcept
{
pNode pNewNode = std::make_unique<node>(t);
push_internal(pNewNode);
}

template<typename T>
void lfQueue<T>::push(const T&& t) noexcept
{
pNode pNewNode = std::make_unique<node>(t);
push_internal(pNewNode);
}

template<typename T>
const T& lfQueue<T>::back() const noexcept
{
Expand Down
34 changes: 23 additions & 11 deletions src/tests/basic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,39 @@ namespace lfQueue
{
namespace tests
{
TEST(lfQueue, test_1)
template<typename T>
void basic_test(T&& a, T&& b)
{

lfQueue<int> queue;
queue.push(3);
EXPECT_EQ(queue.size(),1);
EXPECT_EQ(queue.front(), 3);
EXPECT_EQ(queue.back(),3);
queue.push(a);
EXPECT_EQ(queue.size(), 1);
EXPECT_EQ(queue.front(), a);
EXPECT_EQ(queue.back(), a);

queue.push(5);
queue.push(b);
EXPECT_EQ(queue.size(), 2);
EXPECT_EQ(queue.back(), 5);
EXPECT_EQ(queue.front(),3);
EXPECT_EQ(queue.back(), b);
EXPECT_EQ(queue.front(), a);

queue.pop();
EXPECT_EQ(queue.size(), 1);
EXPECT_EQ(queue.front(), 5);
EXPECT_EQ(queue.back(), 5);
EXPECT_EQ(queue.front(), b);
EXPECT_EQ(queue.back(), b);

queue.pop();
EXPECT_EQ(queue.size(), 0);
}

TEST(lfQueue, test_lValue_push)
{
int a = 3;
int b = 5;
basic_test(a,b);
}

TEST(lfQueue, test_rValue_push)
{
basic_test(3, 5);
}
}
}

0 comments on commit abf84c8

Please sign in to comment.