diff --git a/examples/base/array.cc b/examples/base/array.cc index 08448b5a42..95e81f77f1 100644 --- a/examples/base/array.cc +++ b/examples/base/array.cc @@ -1,11 +1,18 @@ // This file is part of Empirical, https://github.com/devosoft/Empirical -// Copyright (C) Michigan State University, 2016-2017. +// Copyright (C) Michigan State University, 2016-2018. // Released under the MIT Software license; see doc/LICENSE #include "base/array.h" #define A_SIZE 50 +// Function to print an std::array; will it work with emp::array? +template +void ArrayPrint(const std::array & ar) { + for (int x : ar) std::cout << x << " "; + std::cout << std::endl; +} + int main() { emp::array test_array; @@ -14,6 +21,9 @@ int main() test_array[i] = (int) (i * i); } + std::cout << "First array: " << std::endl; + ArrayPrint(test_array); + int sum = 0; for (size_t i = 0; i < A_SIZE; i++) { sum += test_array[i]; diff --git a/examples/data/Makefile b/examples/data/Makefile index 6a842fa741..3ed1fe0a2b 100644 --- a/examples/data/Makefile +++ b/examples/data/Makefile @@ -5,6 +5,7 @@ CFLAGS_version := -std=c++14 # Emscripten compiler information CXX_web := emcc CXX_native := g++ +#CXX_native := clang++ OFLAGS_native_debug := -g -pedantic -DEMP_TRACK_MEM -Wnon-virtual-dtor -Wcast-align -Woverloaded-virtual -Wconversion -Weffc++ OFLAGS_native_opt := -O3 -DNDEBUG diff --git a/examples/timing/pointers.cc b/examples/timing/pointers.cc index ca4e3ac24f..7a50d79cb2 100644 --- a/examples/timing/pointers.cc +++ b/examples/timing/pointers.cc @@ -25,7 +25,7 @@ int main() std::clock_t base_start_time = std::clock(); std::vector v_base(N); - for (size_t i = 0; i < N; i++) v_base[i] = new int((i*7)%N); + for (size_t i = 0; i < N; i++) v_base[i] = new int((int)((i*7)%N)); std::vector v_base2(v_base); std::sort( v_base2.begin(), v_base2.end(), [](int *p1,int *p2){ return *p1 < *p2; } ); v_base.resize(0); @@ -43,7 +43,7 @@ int main() std::clock_t std_start_time = std::clock(); std::vector> v_std(N); - for (size_t i = 0; i < N; i++) v_std[i] = std::make_shared( (i*7)%N ); + for (size_t i = 0; i < N; i++) v_std[i] = std::make_shared( (int)((i*7)%N) ); std::vector> v_std2(v_std); std::sort( v_std2.begin(), v_std2.end(), [](std::shared_ptr p1, std::shared_ptr p2){ return *p1 < *p2; } ); @@ -61,7 +61,7 @@ int main() std::clock_t emp_start_time = std::clock(); std::vector> v_emp(N); - for (size_t i = 0; i < N; i++) v_emp[i] = emp::NewPtr((i*7)%N); + for (size_t i = 0; i < N; i++) v_emp[i] = emp::NewPtr((int)((i*7)%N)); std::vector> v_emp2(v_emp); std::sort( v_emp2.begin(), v_emp2.end(), [](emp::Ptr p1, emp::Ptr p2){ return *p1 < *p2; } ); diff --git a/source/base/array.h b/source/base/array.h index 5e159df127..99368f947a 100644 --- a/source/base/array.h +++ b/source/base/array.h @@ -128,6 +128,12 @@ namespace emp { array(InputIt first, InputIt last) : base_t(first, last), valid(true) { emp_assert(size() == N); } ~array() { valid=false; } // No longer valid when array is deleted. + operator std::array() { + std::array ar; + for (size_t i = 0; i < N; i++) ar[i] = base_t::operator[](i); + return ar; + } + constexpr size_t size() const { return N; } iterator begin() noexcept { return iterator(base_t::begin(), this); } diff --git a/source/base/vector.h b/source/base/vector.h index 9cf23005e5..6796b5769e 100644 --- a/source/base/vector.h +++ b/source/base/vector.h @@ -10,8 +10,8 @@ * This class is a drop-in wrapper for std::vector, adding on bounds checking. * If EMP_NDEBUG is set then it reverts back to std::vector. * - * @todo Need an automatic conversion from emp::vector to std::vector and back to interface with - * non-empirical code. + * @todo Debug code: member functions that take iterators should also take emp iterators that verify + * whether those iterators are valid. */ @@ -62,6 +62,7 @@ namespace emp { const vec_t * v_ptr; int revision; + // @CAO: For the moment cannot create an emp iterator from a base since we don't know vector to use. // iterator_wrapper(const ITERATOR_T & _in) // : ITERATOR_T(_in), v_ptr(nullptr), revision(0) { ; } iterator_wrapper(const ITERATOR_T & _in, const vec_t * _v) diff --git a/source/meta/type_traits.h b/source/meta/type_traits.h index 71513e4e97..587a7b3f55 100644 --- a/source/meta/type_traits.h +++ b/source/meta/type_traits.h @@ -1,5 +1,5 @@ // This file is part of Empirical, https://github.com/devosoft/Empirical -// Copyright (C) Michigan State University, 2016-2017. +// Copyright (C) Michigan State University, 2016-2018. // Released under the MIT Software license; see doc/LICENSE // // Extensions on the standard library type traits to handle Empirical classes diff --git a/source/tools/set_utils.h b/source/tools/set_utils.h index b678165a1f..2289c8f8e1 100644 --- a/source/tools/set_utils.h +++ b/source/tools/set_utils.h @@ -1,7 +1,7 @@ /** * @note This file is part of Empirical, https://github.com/devosoft/Empirical * @copyright Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md - * @date 2016-2017 + * @date 2016-2018 * * @file set_utils.h * @brief Tools to save and load data from classes. @@ -68,7 +68,7 @@ namespace emp { return result; } - /// Compute the set difference of @param s1 and @param s2 (elements that are in S1 but no S2) + /// Compute the set difference of @param s1 and @param s2 (elements that are in S1 but not S2) template std::set difference(std::set & s1, emp::vector s2) { // Based on PierreBdR's answer to https://stackoverflow.com/questions/283977/c-stl-set-difference diff --git a/source/web/JSWrap.h b/source/web/JSWrap.h index d704fa8040..b06da7f2a7 100644 --- a/source/web/JSWrap.h +++ b/source/web/JSWrap.h @@ -1,7 +1,7 @@ /** * @note This file is part of Empirical, https://github.com/devosoft/Empirical * @copyright Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md - * @date 2015-2017 + * @date 2015-2018 * * @file JSWrap.h * @brief Wrap a C++ function and convert it to an integer that can be called from Javascript @@ -116,7 +116,7 @@ namespace emp { arg_var = tmp_var; // @CAO Do we need to free the memory in tmp_var? } - template static void LoadArg(std::array & arg_var){ + template static void LoadArg(emp::array & arg_var){ EM_ASM_ARGS({emp_i.__outgoing_array = emp_i.cb_args[$0];}, ARG_ID); pass_array_to_cpp(arg_var); } @@ -265,7 +265,7 @@ namespace emp { } template - static void StoreReturn(const std::array & ret_var) { + static void StoreReturn(const emp::array & ret_var) { pass_array_to_javascript(ret_var); EM_ASM({ emp_i.cb_return = emp_i.__incoming_array; }); } @@ -292,7 +292,7 @@ namespace emp { } template - static void StoreReturn(const std::array & ret_var, std::string var) { + static void StoreReturn(const emp::array & ret_var, std::string var) { pass_array_to_javascript(ret_var); EM_ASM_ARGS({ emp_i.curr_obj[Pointer_stringify($0)] = emp_i.__incoming_array;}, var.c_str()); } diff --git a/source/web/d3/axis.h b/source/web/d3/axis.h index bf0a910d43..b3335b5c7f 100644 --- a/source/web/d3/axis.h +++ b/source/web/d3/axis.h @@ -1,5 +1,14 @@ -#ifndef __AXIS_H__ -#define __AXIS_H__ +/** + * @note This file is part of Empirical, https://github.com/devosoft/Empirical + * @copyright Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md + * @date 2017-2018 + * + * @file axis.h + * @brief Handle drawing of axes on D3 graphts. + */ + +#ifndef EMP_D3_AXIS_H +#define EMP_D3_AXIS_H #include "../js_utils.h" #include "../../tools/string_utils.h" @@ -171,7 +180,7 @@ namespace D3 { } template - Axis& SetTickValues(std::array values) { + Axis& SetTickValues(emp::array values) { emp::pass_array_to_javascript(values); EM_ASM_ARGS({ @@ -231,7 +240,7 @@ namespace D3 { /// transition, then the rescaling will be animated. template Axis& Rescale(double new_min, double new_max, const D3::SelectionOrTransition & svg){ - this->scale.SetDomain(std::array({{new_min, new_max}})); + this->scale.SetDomain(emp::array{{new_min, new_max}}); ApplyAxis(svg.Select("#"+dom_id)); return *this; } diff --git a/source/web/d3/dataset.h b/source/web/d3/dataset.h index 0844fba976..3293c5d984 100644 --- a/source/web/d3/dataset.h +++ b/source/web/d3/dataset.h @@ -1,5 +1,14 @@ -#ifndef __LOAD_DATA_H__ -#define __LOAD_DATA_H__ +/** + * @note This file is part of Empirical, https://github.com/devosoft/Empirical + * @copyright Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md + * @date 2016-2018 + * + * @file dataset.h + * @brief Tools to maintain data in D3. + */ + +#ifndef EMP_D3_LOAD_DATA_H +#define EMP_D3_LOAD_DATA_H #include @@ -225,7 +234,7 @@ namespace D3 { /// Put the last row of the array into arr template - void GetLastRow(std::array & arr) { + void GetLastRow(emp::array & arr) { EM_ASM_ARGS({ emp_i.__outgoing_array = js.objects[$0][js.objects[$0].length - 1]; }, GetID()); diff --git a/source/web/d3/layout.h b/source/web/d3/layout.h index fe36b1ce8a..6c9c9b5ae3 100644 --- a/source/web/d3/layout.h +++ b/source/web/d3/layout.h @@ -1,5 +1,14 @@ -#ifndef __LAYOUT_H__ -#define __LAYOUT_H__ +/** + * @note This file is part of Empirical, https://github.com/devosoft/Empirical + * @copyright Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md + * @date 2016-2018 + * + * @file layout.h + * @brief Tools for laying out nodes in D3. + */ + +#ifndef EMP_D3_LAYOUT_H +#define EMP_D3_LAYOUT_H #include "d3_init.h" #include "dataset.h" @@ -80,8 +89,8 @@ namespace D3{ make_line = new D3::LinkGenerator("horizontal"); - // std::function(NODE_TYPE, int, int)> projection = [](NODE_TYPE n, int i, int k){ - // return std::array({n.y(), n.x()}); + // std::function(NODE_TYPE, int, int)> projection = [](NODE_TYPE n, int i, int k){ + // return emp::array({n.y(), n.x()}); // }; // // emp::JSWrap(projection, "projection"); @@ -96,8 +105,8 @@ namespace D3{ make_line = new D3::LinkGenerator("horizontal"); - // std::function(NODE_TYPE, int, int)> projection = [](NODE_TYPE n, int i, int k){ - // return std::array({{n.y(), n.x()}}); + // std::function(NODE_TYPE, int, int)> projection = [](NODE_TYPE n, int i, int k){ + // return emp::array({{n.y(), n.x()}}); // }; // // emp::JSWrap(projection, "projection"); @@ -123,7 +132,7 @@ namespace D3{ //to do more with it. It would be nice to return the enter selection for //links too, but C++ makes that super cumbersome, and it's definitely the less //common use case - std::array GenerateNodesAndLinks(Selection svg) { + emp::array GenerateNodesAndLinks(Selection svg) { int node_enter = NextD3ID(); int node_exit = NextD3ID(); int link_enter = NextD3ID(); @@ -179,8 +188,8 @@ namespace D3{ js.objects[$7] = linkExit; }, this->id, data->GetID(), make_line->GetID(), svg.GetID(), node_enter, node_exit, link_enter, link_exit); std::cout << "Done generating" << std::endl; - return std::array({{Selection(node_enter), Selection(node_exit), - Selection(link_enter), Selection(link_exit)}}); + return emp::array{{Selection(node_enter), Selection(node_exit), + Selection(link_enter), Selection(link_exit)}}; } diff --git a/source/web/d3/scales.h b/source/web/d3/scales.h index 8d07c080df..f6f9c23e96 100644 --- a/source/web/d3/scales.h +++ b/source/web/d3/scales.h @@ -1,5 +1,14 @@ -#ifndef __SCALES_H__ -#define __SCALES_H__ +/** + * @note This file is part of Empirical, https://github.com/devosoft/Empirical + * @copyright Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md + * @date 2016-2018 + * + * @file scales.h + * @brief Tools for scaling graph axes in D3. + */ + +#ifndef EMP_D3_SCALES_H +#define EMP_D3_SCALES_H #include "d3_init.h" #include "utils.h" @@ -26,7 +35,7 @@ namespace D3 { /// will be interpolated with a function determined by the type of the scale. /// Array should contain same number of elements as the one used to set the domain. template - Scale& SetRange(std::array values) { + Scale& SetRange(emp::array values) { emp::pass_array_to_javascript(values); EM_ASM_ARGS({js.objects[$0].range(emp_i.__incoming_array);}, this->id); return *this; @@ -40,7 +49,7 @@ namespace D3 { /// Set the input values corresponding to values in the range. /// Array should contain same number of elements as the one used to set the range. template - Scale& SetDomain(std::array values) { + Scale& SetDomain(emp::array values) { emp::pass_array_to_javascript(values); EM_ASM_ARGS({js.objects[$0].domain(emp_i.__incoming_array);}, this->id); return *this; @@ -139,7 +148,7 @@ namespace D3 { LinearScale(bool derived) : IdentityScale(true) {;} template - LinearScale& SetRangeRound(std::array values) { + LinearScale& SetRangeRound(emp::array values) { emp::pass_array_to_javascript(values); EM_ASM_ARGS({js.objects[$0].rangeRound(emp.__incoming_array);}, this->id); return *this; diff --git a/source/web/d3/svg_shapes.h b/source/web/d3/svg_shapes.h index 48737e8e04..2465a66ab6 100644 --- a/source/web/d3/svg_shapes.h +++ b/source/web/d3/svg_shapes.h @@ -1,5 +1,14 @@ -#ifndef __SVG_SHAPES_H__ -#define __SVG_SHAPES_H__ +/** + * @note This file is part of Empirical, https://github.com/devosoft/Empirical + * @copyright Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md + * @date 2016-2018 + * + * @file svg_shapes.h + * @brief Tools to build common SVG shapes. + */ + +#ifndef EMP_D3_SVG_SHAPES_H +#define EMP_D3_SVG_SHAPES_H #include "d3_init.h" #include "selection.h" @@ -28,7 +37,7 @@ namespace D3 { /// Assumes [data] is an array of 2-element arrays describing (x,y) coordinates and makes /// the line that connects them template - std::string Generate(std::array, SIZE> & data){ + std::string Generate(emp::array, SIZE> & data){ emp::pass_array_to_javascript(data); char * buffer = (char *)EM_ASM_INT({ @@ -46,7 +55,7 @@ namespace D3 { /// Draws the path associated with [data] onto the [s] selection (must contain a single SVG) /// element). template - Selection DrawShape(std::array, SIZE> & data, Selection & s) { + Selection DrawShape(emp::array, SIZE> & data, Selection & s) { Selection path = s.Append("path"); path.SetAttr("d", Generate(data)); return path; @@ -65,7 +74,7 @@ namespace D3 { /// If you pass a triple-nested array, it will be treated as an array of paths template - Selection DrawShape(std::array, SIZE>,\ + Selection DrawShape(emp::array, SIZE>,\ SIZE2> & data) { Selection group = Select("svg").Append("g"); for (auto arr: data) { @@ -229,7 +238,7 @@ namespace D3 { /// As an example, the default function expects data like this (array of arrays): /// [[0,0], [1,1], [2,2]] /// And has (a Javascript equivalent of) this accessor: - /// int x(std::array d) {return d[0];} + /// int x(emp::array d) {return d[0];} /// /// If your data instead looked like this (array of Javascript objects with x and y values): /// [{x:0, y:0}, {x:1, y:1}, {x:2, y:2}] @@ -276,7 +285,7 @@ namespace D3 { /// As an example, the default function expects data like this (array of arrays): /// [[0,0], [1,1], [2,2]] /// And has (a Javascript equivalent of) this accessor: - /// int x(std::array d) {return d[1];} + /// int x(emp::array d) {return d[1];} /// /// If your data instead looked like this (array of Javascript objects with x and y values): /// [{x:0, y:0}, {x:1, y:1}, {x:2, y:2}] diff --git a/source/web/d3/test.cc b/source/web/d3/test.cc index 7824633a9f..9e6fcff755 100644 --- a/source/web/d3/test.cc +++ b/source/web/d3/test.cc @@ -29,14 +29,14 @@ void mouseover(int id){ void make_graph() { D3::Selection svg = D3::Selection("body").Append("svg"); - //std::array, 5> data; + //emp::array, 5> data; //EM_ASM({emp.__outgoing_array = emp.__incoming_data;}); //emp::pass_array_to_cpp(data); D3::Dataset data = D3::Dataset(); D3::Axis x_axis = D3::Axis(); x_axis.SetScale(D3::LinearScale()); - std::array domain = {0, 60}; - std::array range = {0, 250}; + emp::array domain = {0, 60}; + emp::array range = {0, 250}; x_axis.GetScale().SetDomain(domain); x_axis.GetScale().SetRange(range); x_axis.SetTicks(3); @@ -59,7 +59,7 @@ int main() emp::JSWrap(make_graph, "make_graph"); EM_ASM({emp.__outgoing_array = ["hi", "eeee", "l", "l", "o"]; }); - std::array new_array; + emp::array new_array; emp::pass_array_to_cpp(new_array); std::cout << new_array[0] << " " << new_array[1] << " " << new_array[2] << std::endl; @@ -77,9 +77,9 @@ int main() std::cout << n_objects() << std::endl; D3::LinearScale s = D3::LinearScale(); - s.SetRange(std::array({2,3})); + s.SetRange(emp::array({2,3})); - std::array test_data = {10,30,60}; + emp::array test_data = {10,30,60}; JSDataObject test_obj_1; test_obj_1.val() = 10; test_obj_1.word() = "hi"; @@ -90,11 +90,11 @@ int main() test_obj_2.word() = "hi2"; test_obj_2.val2() = 11.2; - std::array test_data_2 = {test_obj_1, test_obj_2}; + emp::array test_data_2 = {test_obj_1, test_obj_2}; - std::array, 5> test_path = {{{0,0}, {0,10}, {10,10}, {20,20}, {30, 30}}}; + emp::array, 5> test_path = {{{0,0}, {0,10}, {10,10}, {20,20}, {30, 30}}}; - std::array, 2>, 3> test_paths = {{ {{{0,0}, {100,0}}}, {{{0,10}, {100,100}}}, {{{20,20}, {300, 300}}} }}; + emp::array, 2>, 3> test_paths = {{ {{{0,0}, {100,0}}}, {{{0,10}, {100,100}}}, {{{20,20}, {300, 300}}} }}; //D3::ShapesFromData(test_data, "circle"); //EM_ASM({d3.select("svg").selectAll("circle").data([{val:5, word:"hi", val2:6.3}]).enter().append("circle")}); diff --git a/source/web/d3/visualizations.h b/source/web/d3/visualizations.h index 923b114a70..5cb3fef8b3 100644 --- a/source/web/d3/visualizations.h +++ b/source/web/d3/visualizations.h @@ -1,5 +1,14 @@ -#ifndef VISUALIZATION_UTILS_H -#define VISUALIZATION_UTILS_H +/** + * @note This file is part of Empirical, https://github.com/devosoft/Empirical + * @copyright Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md + * @date 2017-2018 + * + * @file visualizations.h + * @brief Tools to build D3 visualizations. + */ + +#ifndef EMP_VISUALIZATION_UTILS_H +#define EMP_VISUALIZATION_UTILS_H #include #include @@ -181,10 +190,10 @@ class DotPlot : public D3Visualization { //Set up scales y_scale = new D3::LinearScale(); x_scale = new D3::LinearScale(); - y_scale->SetDomain(std::array({{highest*value_growth_margin, lowest*value_loss_margin}})); - y_scale->SetRange(std::array({{margin, GetHeight() - margin}})); - x_scale->SetDomain(std::array({{0, x_max}})); - x_scale->SetRange(std::array({{axis_width, GetHeight()-margin}})); + y_scale->SetDomain(emp::array{{highest*value_growth_margin, lowest*value_loss_margin}}); + y_scale->SetRange(emp::array{{margin, GetHeight() - margin}}); + x_scale->SetDomain(emp::array{{0, x_max}}); + x_scale->SetRange(emp::array{{axis_width, GetHeight()-margin}}); //Set up axis ax = new D3::Axis("right"); @@ -316,7 +325,7 @@ class HistogramChart : public D3Visualization { // } }; -template , +template , typename X_SCALE_TYPE = D3::LinearScale, typename Y_SCALE_TYPE = D3::LinearScale > class LineGraph : public D3Visualization { @@ -391,10 +400,10 @@ class LineGraph : public D3Visualization { //Set up scales y_scale = new Y_SCALE_TYPE(); x_scale = new X_SCALE_TYPE(); - y_scale->SetDomain(std::array({{y_max, y_min}})); - y_scale->SetRange(std::array({{y_margin, (double)GetHeight() - axis_width}})); - x_scale->SetDomain(std::array({{x_min,x_max}})); - x_scale->SetRange(std::array({{axis_width, GetWidth()-x_margin}})); + y_scale->SetDomain(emp::array{{y_max, y_min}}); + y_scale->SetRange(emp::array{{y_margin, (double)GetHeight() - axis_width}}); + x_scale->SetDomain(emp::array{{x_min,x_max}}); + x_scale->SetRange(emp::array{{axis_width, GetWidth()-x_margin}}); //Set up axes x_axis = new D3::Axis("bottom", variables[0]); @@ -705,7 +714,7 @@ class LineGraph : public D3Visualization { // //We can't draw a line on the first update if (prev_data[0] >= 0 ){ - std::array line_data; + emp::array line_data; line_data[0] = prev_data; line_data[1] = data[0]; @@ -717,7 +726,7 @@ class LineGraph : public D3Visualization { } // If it isn't nested, D3 will think it's 2 separate points - std::array new_point = {{data[0]}}; + emp::array new_point = {{data[0]}}; // GetSVG()->SelectAll(".data-point").Log(); GetSVG()->SelectAll(".data-point") .Data(new_point, GetID()+"return_x") diff --git a/source/web/js_utils.h b/source/web/js_utils.h index b126764cbb..52c6eaacc8 100644 --- a/source/web/js_utils.h +++ b/source/web/js_utils.h @@ -1,7 +1,7 @@ /** * @note This file is part of Empirical, https://github.com/devosoft/Empirical * @copyright Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md - * @date 2015-2017 + * @date 2015-2018 * * @file js_utils.h * @brief Tools for passing data between C++ and Javascript. @@ -218,7 +218,7 @@ namespace emp { // This version of the function handles nested arrays with recursive calls // until a non-array type is found. template - void pass_array_to_javascript(std::array, SIZE2> values, + void pass_array_to_javascript(emp::array, SIZE2> values, emp::vector recursive_el = emp::vector()) { // Initialize if this is the first call to this function @@ -296,7 +296,7 @@ namespace emp { // Don't worry about the recurse argument - it's for handling nested arrays // internally template - void pass_array_to_cpp(std::array & arr, bool recurse = false) { + void pass_array_to_cpp(emp::array & arr, bool recurse = false) { //Figure out type stuff std::map map_type_names = get_type_to_string_map(); @@ -397,7 +397,7 @@ namespace emp { // Chars aren't one of the types supported by setValue, but by treating them // as strings in Javascript we can pass them out to a C++ array template - void pass_array_to_cpp(std::array & arr, bool recurse = false) { + void pass_array_to_cpp(emp::array & arr, bool recurse = false) { emp_assert(arr.size() == EM_ASM_INT_V({return emp_i.__outgoing_array.length})); @@ -446,7 +446,7 @@ namespace emp { // We can handle strings in a similar way template - void pass_array_to_cpp(std::array & arr, bool recurse = false) { + void pass_array_to_cpp(emp::array & arr, bool recurse = false) { emp_assert(arr.size() == EM_ASM_INT_V({return emp_i.__outgoing_array.length})); @@ -515,7 +515,7 @@ namespace emp { // We can handle nested arrays through recursive calls on chunks of them template - void pass_array_to_cpp(std::array, SIZE> & arr, bool recurse = false) { + void pass_array_to_cpp(emp::array, SIZE> & arr, bool recurse = false) { emp_assert(arr.size() == EM_ASM_INT_V({return emp_i.__outgoing_array.length})); diff --git a/tests/web/js_utils.cc b/tests/web/js_utils.cc index 6825395606..f51f429ffb 100644 --- a/tests/web/js_utils.cc +++ b/tests/web/js_utils.cc @@ -29,7 +29,7 @@ int main(int argc, char* argv[]) { emp::Initialize(); //Test passing arrays to Javascript - std::array test_data = {{10,30,60}}; + emp::array test_data = {{10,30,60}}; JSDataObject test_obj_1; test_obj_1.val() = 10; @@ -41,13 +41,13 @@ int main(int argc, char* argv[]) { test_obj_2.word() = "hi2"; test_obj_2.val2() = 11.2; - std::array test_data_2 = {{test_obj_1, test_obj_2}}; + emp::array test_data_2 = {{test_obj_1, test_obj_2}}; - std::array, 1>, 5> horrible_array = {{{{{{0,0}}}}, {{{{0,10}}}}, {{{{10,10}}}}, {{{{20,20}}}}, {{{{30, 30}}}}}}; + emp::array, 1>, 5> horrible_array = {{{{{{0,0}}}}, {{{{0,10}}}}, {{{{10,10}}}}, {{{{20,20}}}}, {{{{30, 30}}}}}}; - std::array, 2> test_data_4 = {{{{test_obj_1, test_obj_2}}, {{test_obj_2, test_obj_2}}}}; + emp::array, 2> test_data_4 = {{{{test_obj_1, test_obj_2}}, {{test_obj_2, test_obj_2}}}}; - std::array, 1> string_arr = {{{{"do", "strings", "work", "in", "arrays?"}}}}; + emp::array, 1> string_arr = {{{{"do", "strings", "work", "in", "arrays?"}}}}; emp::vector int_vec = {5,1,2,3,6}; @@ -111,7 +111,7 @@ int main(int argc, char* argv[]) { //Test passing arrays to C++ //Test ints EM_ASM({emp_i.__outgoing_array = [5, 1, 3]}); - std::array test_arr_1; + emp::array test_arr_1; emp::pass_array_to_cpp(test_arr_1); EMP_TEST_VALUE(test_arr_1[0], "5"); EMP_TEST_VALUE(test_arr_1[1], "1"); @@ -119,7 +119,7 @@ int main(int argc, char* argv[]) { //Test floats EM_ASM({emp_i.__outgoing_array = [5.2, 1.5, 3.1]}); - std::array test_arr_2; + emp::array test_arr_2; emp::pass_array_to_cpp(test_arr_2); EMP_TEST_VALUE(test_arr_2[0], "5.2"); EMP_TEST_VALUE(test_arr_2[1], "1.5"); @@ -127,7 +127,7 @@ int main(int argc, char* argv[]) { //Test doubles EM_ASM({emp_i.__outgoing_array = [5.2, 1.5, 3.1]}); - std::array test_arr_3; + emp::array test_arr_3; emp::pass_array_to_cpp(test_arr_3); EMP_TEST_VALUE(test_arr_3[0], "5.2"); EMP_TEST_VALUE(test_arr_3[1], "1.5"); @@ -143,7 +143,7 @@ int main(int argc, char* argv[]) { //Test chars EM_ASM({emp_i.__outgoing_array = ["h", "i", "!"]}); - std::array test_arr_4; + emp::array test_arr_4; emp::pass_array_to_cpp(test_arr_4); EMP_TEST_VALUE(test_arr_4[0], "h"); EMP_TEST_VALUE(test_arr_4[1], "i"); @@ -157,7 +157,7 @@ int main(int argc, char* argv[]) { //Test std::strings EM_ASM({emp_i.__outgoing_array = ["jello", "world", "!!"]}); - std::array test_arr_5; + emp::array test_arr_5; emp::pass_array_to_cpp(test_arr_5); EMP_TEST_VALUE(test_arr_5[0], "jello"); EMP_TEST_VALUE(test_arr_5[1], "world"); @@ -170,7 +170,7 @@ int main(int argc, char* argv[]) { //Test nested arrays EM_ASM({emp_i.__outgoing_array = [[4,5], [3,1], [7,8]]}); - std::array, 3> test_arr_6; + emp::array, 3> test_arr_6; emp::pass_array_to_cpp(test_arr_6); EMP_TEST_VALUE(test_arr_6[0][0], "4"); EMP_TEST_VALUE(test_arr_6[0][1], "5"); @@ -193,7 +193,7 @@ int main(int argc, char* argv[]) { EM_ASM({emp_i.__outgoing_array = [[["Sooo", "many"], ["strings", "here"]], [["and", "they're"], ["all", "nested"]], [["in", "this"], ["nested", "array!"]]];}); - std::array, 2>, 3> test_arr_7; + emp::array, 2>, 3> test_arr_7; emp::pass_array_to_cpp(test_arr_7); EMP_TEST_VALUE(test_arr_7[0][0][0], "Sooo"); EMP_TEST_VALUE(test_arr_7[0][0][1], "many"); diff --git a/tests/web/test_visualizations.cc b/tests/web/test_visualizations.cc index 27f7fc7176..5a0f34f268 100644 --- a/tests/web/test_visualizations.cc +++ b/tests/web/test_visualizations.cc @@ -29,7 +29,7 @@ struct LineageTreeNode { emp::web::Document doc("line_graph"); emp::web::Document tree_viz("tree_viz"); -emp::web::LineGraph > line_graph("x", "y", 500, 250); +emp::web::LineGraph > line_graph("x", "y", 500, 250); emp::web::TreeVisualization tree(500, 250); D3::Selection example_selection; @@ -76,7 +76,7 @@ int MakeSVG(){ } int BindData() { - D3::Selection temp_circles = example_selection.SelectAll("circle").Data(std::array({{8,3,5,2}})); + D3::Selection temp_circles = example_selection.SelectAll("circle").Data(emp::array{{8,3,5,2}}); circles = temp_circles.Enter().Append("circle").Merge(temp_circles); return circles.GetID(); } @@ -397,7 +397,7 @@ int main() { emp::JSWrap([](){ax.SetScale(scale);}, "TestSetScale"); emp::JSWrap([](){return ax.GetScale().GetID();}, "TestGetScale"); - emp::JSWrap([](){ax.SetTickValues(std::array({{4,5,7}}));}, "TestSetTickValues"); + emp::JSWrap([](){ax.SetTickValues(emp::array{{4,5,7}});}, "TestSetTickValues"); emp::JSWrap([](){ax.SetTickSize(.2);}, "TestSetTickSize"); emp::JSWrap([](){ax.SetTickSizeInner(.7);}, "TestSetInnerTickSize"); emp::JSWrap([](){ax.SetTickSizeOuter(1.1);}, "TestSetOuterTickSize");