Created
October 20, 2011 06:18
-
-
Save TyounanMOTI/1300548 to your computer and use it in GitHub Desktop.
std::valarray initialization from raw pointer copies deeply.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <gtest/gtest.h> | |
#include <valarray> | |
TEST(ValarrayTest, InitializeWithRawPointer) { | |
int *p = (int*)malloc(sizeof(int)*10); | |
p[0] = 4; | |
ASSERT_EQ(4, p[0]); | |
std::valarray<int> subject(p, 10); | |
ASSERT_EQ(4, subject[0]); | |
p[0] = 6; | |
EXPECT_EQ(6, subject[0]); // FAIL! | |
free(p); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment