Elements of Programming

Source code

The programs in Elements of Programming are written in a subset of C++ that is specified in Appendix B of the book. A parser written by Sean Parent for this subset is here (mirror); the header file exp_parser.hpp (mirror) contains a grammar that is very similar to the one in Appendix B.

eop-code.zip (ZIP archive of all code)

eop.h - algorithms and machines from the book plus variations mentioned in text, exercises, etc.
intrinsics.h - implementations from Appendix B.2 (requires, addressof, pointer) plus in-place construct and destroy
integers.h - implementation of special-case Integer procedures for integral types
pointers.h - definitions of type functions and global functions from dereferenceable and iterator concepts for pointer(T) and constant references
type_functions.h - implementations of type functions
tests.h - regression tests
drivers.h - drivers for interactive use of algorithms
measurements.h - measurements
assertions.h - run-time assertion for regression tests that works in release or debug build
print.h - print various types to standard output
read.h - read various types from standard input
eop.cpp - main program for interactive use, regression testing, and measurement of algorithms

Machines

A machine is a sequence of statements used as a component of many algorithms.

copy_backward_step
copy_step
count_down
linker_to_head
linker_to_tail
merge_n_step_0
merge_n_step_1
reverse_copy_backward_step
hyperpage
reverse_copy_step
reverse_swap_step
swap_step
traverse_step
tree_rotate

Algorithms

abs
add_to_counter
all
begin
bifurcate_compare
bifurcate_compare_nonempty
bifurcate_equivalent
bifurcate_equivalent_nonempty
bifurcate_similar
bifurcate_similar_nonempty
circular
circular_nonterminating_orbit
collision_point
collision_point_nonterminating_orbit
combine_copy
combine_copy_backward
combine_linked_nonempty
combine_ranges
compare_strict_or_reflexive
complement
complement_of_converse
connection_point
connection_point_nonterminating_orbit
convergent_point
converse
copy
copy_backward
copy_bounded
copy_if
copy_n
copy_select
count_if
cycle_from
cycle_to
distance
empty
end
equal
euclidean_norm
exchange_values
fast_subtractive_gcd
fibonacci
find
find_adjacent_mismatch
find_adjacent_mismatch_forward
find_backward_if
find_if
find_if_not_unguarded
find_if_unguarded
find_last
find_mismatch
find_n
find_not
for_each
for_each_n
gcd
height
height_recursive
increment
is_left_successor
is_right_successor
k_rotate_from_permutation_indexed
k_rotate_from_permutation_random_access
largest_doubling
less
lexicographical_compare
lexicographical_equal
lexicographical_equivalent
lexicographical_less
lower_bound_n
lower_bound_predicate
median_5
memory-adaptive,
merge_copy
merge_copy_backward
merge_linked_nonempty
merge_n_adaptive
merge_n_with_buffer
none
not_all
orbit_structure
orbit_structure_nonterminating_orbit
partition_bidirectional
partition_copy
partition_copy_n
partition_linked
partition_point
partition_point_n
partition_semistable
partition_single_cycle
partition_stable_iterative
partition_stable_n
partition_stable_n_adaptive
partition_stable_n_nonempty
partition_stable_singleton
partition_stable_with_buffer
partition_trivial
partitioned_at_point
phased_applicator
potential_partition_point
power
power_accumulate
power_accumulate_positive
power_left_associated
power_right_associated
power_unary
predicate_source
quotient_remainder
quotient_remainder_nonnegative
quotient_remainder_nonnegative_iterative
reachable
reachable_nonempty
reduce
reduce_balanced
reduce_nonempty
reduce_nonzeroes
relation_source
remainder
remainder_nonnegative
remainder_nonnegative_iterative
reverse_append
reverse_bidirectional
reverse_copy
reverse_copy_backward
reverse_indexed
reverse_n_adaptive
reverse_n_bidirectional
reverse_n_forward
reverse_n_indexed
reverse_n_with_buffer
reverse_swap_ranges
reverse_swap_ranges_bounded
reverse_swap_ranges_n
reverse_with_temporary_buffer
rotate
rotate_bidirectional_nontrivial
rotate_cycles
rotate_forward_annotated
rotate_forward_nontrivial
rotate_forward_step
rotate_indexed_nontrivial
rotate_nontrivial
rotate_partial_nontrivial
rotate_random_access_nontrivial
rotate_with_buffer_backward_nontrivial
rotate_with_buffer_nontrivial
select_0_2
select_0_3
select_1_2
select_1_3
select_1_3_ab
select_1_4
select_1_4_ab
select_1_4_ab_cd
select_2_3
select_2_5
select_2_5_ab
select_2_5_ab_cd
size
slow_quotient
slow_remainder
some
sort_linked_nonempty_n
sort_n
sort_n_adaptive
sort_n_with_buffer
split_copy
split_linked
subtractive_gcd
subtractive_gcd_nonzero
swap
swap_basic
swap_ranges
swap_ranges_bounded
swap_ranges_n
terminating
transpose_operation
traverse
traverse_nonempty
traverse_phased_rotating
traverse_rotating
underlying_ref
upper_bound_n
upper_bound_predicate
weight
weight_recursive
weight_rotating